获取当前页面的完整 URL (PHP)
我正在此页面上工作: http://localhost/projectname/custom.php
两者 和
不提供完整位置。我应该使用什么来获取完整的 url 位置?
I'm working on this page: http://localhost/projectname/custom.php
Both <?php echo $_SERVER['REQUEST_URI']; ?>
and <?php echo $PHP_SELF; ?>
don't give full location. What should I use to grab the full url location?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
据我所知,没有本地方法,但你可以使用这个:
There isn't a native method as far as I know, but you could use this:
例如,如果您尝试将变量添加回通过链接跟踪脚本传递的 URL 末尾,则可以尝试以下操作:
在本例中,“link”、“id”和“type”是变量我需要跟踪,但我想要跟踪的 URL 末尾有一个变量,该变量被我的脚本删除,就好像它是发送给它的查询的一部分一样;我需要先将其添加回链接 URL,然后再将其传递给 header("Location:".$link)。
如果这就是您想要实现的目标,那么效果很好并且比上面的示例更短。
If you are trying to add variables back onto the end of an URL that you are passing through a link tracking script, for example, you could try this:
In this case, "link", "id" and "type" were the variables I needed for the tracking, but the URL I wanted to track had a variable on the end of it that got stripped off by my script as if it was part of the query being sent to it; I needed the add it back to the link URL before passing it to header("Location:".$link).
If this is what you are trying to achieve this works great and is shorter than above example.
检查这个...有点长而且脏,但效果很好...
check this one... a bit long and dirty but works good...
我发现这段代码非常有帮助
I found this code very helpful