【问题标题】:# in URL skipping all parameter after that# 在 URL 之后跳过所有参数
【发布时间】:2015-08-07 05:26:31
【问题描述】:

当使用 get 方法提交表单时,如果我们在任何字段中传递 # 字符,它会跳过该字段之后的所有参数。

例如

bookmy_car.php?pod=6&room_id=32&starthour=14&startminute=00&startday=07&startmonth=08&startyear=2015&endhour=16&endminute=00&endday=07&endmonth=08&endyear=2015&end_date=1438927200&email_conf=1&cost_code=&desc=旅行说明&trip_comment#= >&day_rate=68.00&hourly_rate=6.60&hourly_km_rate=0.35&dur_hours=2 hours&location_charge=0.00&damage_cover_charge=5.00&total_free_kms=&longterm=0&rt=&minbooking=3600&returl=&returl_newid=&rep_id=&edit_type=&insPlanid=3&plan_name=goOccasional&id=3&driver_username_id=2&

我们如何保护它?我试过JavaScript的escape()encodeURI()函数,没用。

【问题讨论】:

标签: javascript php html


【解决方案1】:

我同意@dgsq。但我更喜欢只使用encodeURI,这样他就可以得到下一页中的uri。

alert( encodeURI('&trip_comment=#&day_rate=68.00') )

【讨论】:

  • 解决不了,我之前已经试过了。做一件事创建一个php页面,然后打印我提到并看到的url的print_r($_GET)。
【解决方案2】:

这是因为查询字符串 # 中的 hashbang 被解释为 location.hash 并热处理为 GET 参数。您需要在使用 URI 之前对其进行正确编码。例如encodeURIComponent:

alert( encodeURIComponent('trip_comment=#') )

【讨论】:

  • 解决不了,我之前已经试过了。做一件事创建一个php页面,然后打印我提到并看到的url的print_r($_GET)。
  • 您需要对GET参数进行编码。所以trip_comment=# 变成了trip_comment%3D%23。您应该理想地编码每个参数。不确定您如何构建 URL,但您应该使用正确的方法。 JS和PHP都有。
猜你喜欢
  • 2013-10-07
  • 1970-01-01
  • 1970-01-01
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-28
相关资源
最近更新 更多