如何使用PHP在地址栏上获取完整的URL [英] How to get full URL on the address bar using PHP

查看:43
本文介绍了如何使用PHP在地址栏上获取完整的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
获取整个URL,包括查询字符串和锚点

我的网址类似于 www.domain.com/#!/用户名(就像在Twitter中一样).

I have my url like www.domain.com/#!/username (just like in twitter).

如何检索完整的URL(上面的整个字符串),包括'#!'之后的子字符串.在使用PHP或Javascript的地址中?

How can I retrieve the full URL (the whole string above) including the substring after '#!' in the address using PHP or Javascript??

推荐答案

在JavaScript中,除非发生其他情况,否则您应该能够从 document.location 获取完整的URL.,(例如 var URLstring = document.location; ).

In JavaScript, unless you've got something else going on, you should be able to get the full URL from document.location, (so var URLstring = document.location; for example).

在PHP中,正如其他人指出的那样,这是不可能实现的,因为哈希的工作方式(它在页面内导航,并且不触发页面重新加载,因此服务器永远不会知道它,除非JS调用Ajax.在服务器上触发脚本的功能).

In PHP, as others have noted, this is impossible due to the way the hash works (it navigates within the page, and does not trigger a page-reload so the server never knows about it, unless the JS calls an Ajax function that triggers a script on the server).

这篇关于如何使用PHP在地址栏上获取完整的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆