PHP标头:参数值在#

PHP标头:参数值在#,php,httprequest,Php,Httprequest,我在PHP中使用以下代码进行重定向 header("Location:restaurantsList.php?msg=Restaurant 100#we updated successfully"); 在restaurantsList.php中,当我试图获取请求参数时,然后获取以下数组 Array ( [msg] => Restaurant 100 ) 参数值在“#”之后被截断 如果在param中传递任何普通文本(不带#),那么我得到的是整个字符串 即使字符串将包含#?您的查询字符串

我在PHP中使用以下代码进行重定向

header("Location:restaurantsList.php?msg=Restaurant 100#we updated successfully");
restaurantsList.php
中,当我试图获取
请求参数时,然后获取以下数组

Array ( [msg] => Restaurant 100 ) 
参数值在
“#”之后被截断

如果在param中传递任何普通文本(不带#),那么我得到的是整个字符串

即使字符串将包含
#

您的查询字符串中应包含特殊字符,以便您的URL看起来像:

header("Location:restaurantsList.php?msg=Restaurant%20100%23we%20updated%20successfully");
您应该在查询字符串中添加特殊字符,以便您的URL如下所示:

header("Location:restaurantsList.php?msg=Restaurant%20100%23we%20updated%20successfully");
#
符号用于锚定链接,因此如果在URL中用作“数据”,则必须对其进行编码。您可以使用PHP函数来实现这一点。
#
符号将转换为
%23

#
符号用于锚定链接,因此如果在URL中用作“数据”,则必须对其进行编码。您可以使用PHP函数来实现这一点。
#
符号将在url
#
中转换为
%23
,其行为类似于调用
片段标识符的散列标记

Javascript:
window.location.hash
;//这是以
#
标记开头的返回标记

您需要在服务器端代码中对url组件进行编码,以保存消息

header("Location:restaurantsList.php?msg=". 
      urlencode("Restaurant 100#we updated successfully"));

在url
#
中,其行为类似于调用
片段标识符的散列标签

Javascript:
window.location.hash
;//这是以
#
标记开头的返回标记

您需要在服务器端代码中对url组件进行编码,以保存消息

header("Location:restaurantsList.php?msg=". 
      urlencode("Restaurant 100#we updated successfully"));


您需要对
msg=
之后的字符串进行
urlencode

header("Location:restaurantsList.php?msg=" . urlencode("Restaurant 100#we updated successfully");

您需要对
msg=
之后的字符串进行
urlencode

header("Location:restaurantsList.php?msg=" . urlencode("Restaurant 100#we updated successfully");

尝试对参数进行编码并在接收时发送和解码尝试对参数进行编码并在接收时发送和解码