从 php 访问主题标签后的 URI 变量的最佳方法是什么?
我有 Javascript 更新我的 URI,如下所示:
/index.php?page=list#page=news
但我想让 page=news 以某种方式从我的服务器访问,以便在复制和粘贴 URI 时,它会转到新闻页面。最好的方法是什么?
我尝试了 $_SERVER['REQUEST_URI']
但存储在 $_SERVER
中的所有内容都位于哈希标记之前。
I have Javascript updating my URI as below:
/index.php?page=list#page=news
But I would like to make page=news accessible somehow from my server so that when the URI is copied and pasted, it would go to the news page. What is the best way to do this?
I tried $_SERVER['REQUEST_URI']
but everything stored in $_SERVER
is before the hash tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。该数据称为片段,保留用于客户端处理,因此永远不会发送到服务器。
利用该片段的唯一方法是让 Javascript 在某个时刻进行干预。这可能意味着检查页面
onload
上的哈希标签,然后显示正确的数据。您可以通过 Javascript 加载整个页面。虽然它会破坏任何关闭 Javascript 的人的兼容性,但它会确保哈希标签最终发送到 PHP
基本上,它看起来像这样:
(请注意,在上面,
page=list
将被page=news
覆盖,因此$_GET['page']
将是 < code>news.(这个问题是一个非常重复的问题)
You can't. That data, called the fragment, is reserved for client side processing and thus is never sent to the server.
The only way to utilize the fragment is to have Javascript intervene at some point. This probably means checking for a hash-tag on the page
onload
, and then displaying the proper data.You could make your entire page loaded via Javascript. While it would kill compatability for anyone who turned off Javascript, it would ensure that the hash tag eventually gets sent to PHP
Basically, it would look something like this:
(Note that in the above,
page=list
wil be overriden bypage=news
, so$_GET['page']
will benews
.(And this question is very much a duplicate question)