如何使用PHP获取脚本的当前URL?

前端之家收集整理的这篇文章主要介绍了如何使用PHP获取脚本的当前URL?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > getting current URL2
如何使用PHP获取脚本的当前URL?
请参阅 PHP Get Current URL

Sometimes it is not as straightforward
as one may think to get the current
url to use it inside your application.
Here is a snippet that I use to fetch
the current URL and use it in a
script. The current url (whether http
or https) is now a local variable that
you can do with as you please.

$url = "http".(!empty($_SERVER['HTTPS'])?"s":"").
"://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

Note: You should groom this value before using in anything sensitive,like a sql query.

原文链接:https://www.f2er.com/php/130979.html

猜你在找的PHP相关文章