如何获取包含'#'的url通过php在其中?
可能的重复:
用php检索url中的哈希值?
我有一个网址中包含书签的页面,例如
http://www.abc.com/page_url#bookmark
iam 使用 $_SERVER['HTTP_HOST']
和 $_SERVER["REQUEST_URI"]
获取 url,但其 gigvng URL 最多可达 http://www.abc.com/page_url 即它没有在其中提供我的书签链接。
我如何在 php 中获取完整的 url(带有“#”内容)???
编辑:
看看我想要做的是我想在我的网址中添加“/”,即如果网址是 http://www.abc.com/page_url#bookmark 然后我想将其重定向到 http://www.abc.com/page_url#bookmark/ 。当我使用 $_SERVER["REQUEST_URI"] 执行此操作时,其结果为 http://www.abc.com/page_url/#bookmark 这是错误的。 现在请告诉我该怎么做???
Possible Duplicate:
retrieve the hash in the url with php?
iam having a page that is containg bookmark in its url like
http://www.abc.com/page_url#bookmark
iam using $_SERVER['HTTP_HOST']
and $_SERVER["REQUEST_URI"]
to get the url but its gigvng URL only upto
http://www.abc.com/page_url i.e. its not giving my bookmarked link in it.
How can i fetch my complete url(with '#' content) in php????
Edit:
see what i want to do is i want to add '/' in my URL i.e. if a URL is http://www.abc.com/page_url#bookmark then i want to redirect it to http://www.abc.com/page_url#bookmark/ .when im doing this with $_SERVER["REQUEST_URI"] its resulting into http://www.abc.com/page_url/#bookmark which is wrong.
Now plz tell how can i do this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大多数浏览器在请求 URL 时不会发送 #fragment,而是在内部处理它......因此 PHP 无法访问该信息
Most browsers don't send the #fragment when requesting a URL, but handle it internally... so PHP has no access to that information
请求网页时,浏览器不会向网络服务器发送该信息(称为“片段”)。事实上,它甚至可能根本不发出请求(如果您单击指向同一页面但不同片段的链接)。
做到这一点的唯一方法是使用 Javascript。您可以使用 self.document.location.hash 获取片段。然后您可以发出单独的请求(例如ajax)来向服务器发送该信息。
这将很有用,例如存储用户在点击链接时登陆的部分的统计信息,但是您可以根据片段更改页面在服务器端呈现的方式(当然,您可以使用 javascript 将用户重定向到另一个页面) ,或者到同一页面传递查询字符串中的片段,以便可以以不同的方式呈现)。
The browser doesn't send the webserver that information (called the "fragment") when requesting a web page. In fact, it may even not make a request at all (if you click on an link to the same page, but a different fragment).
The only way to do this is with Javascript. You can fetch the fragment with
self.document.location.hash
. Then you can make a separate request (e.g. ajax) to send the server that information.This would be useful e.g. to store statistics on which sections users have landed when they followed a link, but you can change how the page rendered server-side based on the fragment (you could of course, with javascript, redirect the user to another page, or to the same page passing the fragment in the query string so that it could then be rendered differently).