假设URL为:

www.example.com/?val=1#part2

PHP可以使用GET数组读取请求变量val1。

哈希值part2也是可读的吗?或者这仅仅取决于浏览器和JavaScript?


当前回答

是的,你可以:

使用此方法可以防止错误:

<script> 
query=location.hash;
document.cookie= 'anchor'+query;
</script>

当然,在PHP中,爆炸那个小狗,得到其中一个值

$split = explode('/', $_COOKIE['anchor']);
print_r($split[1]); //to test it, use print_r. this line will print the value after the anchortag

其他回答

哈希值不会被发送到服务器,所以不会。

它可以从Javascript中检索-作为window.location.hash。从那里,你可以用Ajax将其发送到服务器,或者将其编码并放入url中,然后可以传递到服务器端。

URI中#后面的部分被称为“片段”,根据定义,仅在客户端可用/处理(参见https://en.wikipedia.org/wiki/Fragment_identifier)。

在客户端,可以使用带有window.location.hash的javaScript进行访问。

主要的问题是浏览器甚至不会发送带有片段部分的请求。片段部分在浏览器中被解析。它可以通过JavaScript访问。

无论如何,您可以使用parse_url()将URL解析为位,包括片段部分,但这显然不是您的情况。

是的,你可以:

使用此方法可以防止错误:

<script> 
query=location.hash;
document.cookie= 'anchor'+query;
</script>

当然,在PHP中,爆炸那个小狗,得到其中一个值

$split = explode('/', $_COOKIE['anchor']);
print_r($split[1]); //to test it, use print_r. this line will print the value after the anchortag