从 php 访问主题标签后的 URI 变量的最佳方法是什么?

发布于 2024-08-19 22:19:15 字数 257 浏览 4 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[旋木] 2024-08-26 22:19:15

你不能。该数据称为片段,保留用于客户端处理,因此永远不会发送到服务器。

利用该片段的唯一方法是让 Javascript 在某个时刻进行干预。这可能意味着检查页面 onload 上的哈希标签,然后显示正确的数据。

您可以通过 Javascript 加载整个页面。虽然它会破坏任何关闭 Javascript 的人的兼容性,但它会确保哈希标签最终发送到 PHP

基本上,它看起来像这样:

  • PHP 发送页面
  • Javascript 读取哈希标签
  • 创建一个带有哈希标签参数的 URL (loader.hashtag)。 php?page=list&page=news)
    (请注意,在上面,page=list 将被 page=news 覆盖,因此 $_GET['page'] 将是 < code>news.
  • AJAX 调用 PHP
  • 将内容加载到 div 中

(这个问题是一个非常重复的问题)

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:

  • PHP Sends Page
  • Javascript reads the hastag
  • Make a URL with a hashtag parameter (loader.php?page=list&page=news)
    (Note that in the above, page=list wil be overriden by page=news, so $_GET['page'] will be news.
  • AJAX call to PHP
  • Load the content into a div.

(And this question is very much a duplicate question)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文