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

标签 php url

<分区>

如何使用 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.

关于php - 如何使用 PHP 获取脚本的当前 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1871770/

相关文章:

PHP 将 DATETIME 转换为时间前函数,秒,分钟,小时,天等

javascript - 如何在 $http.post() 之后从 Angular 导航到 php 页面

php - php 的 crontab 开始了,但有时并没有结束

c# - 从 URL 字符串中删除父路径的最快、最干净的方法是什么?

php - 替换 CSS url() 的?

php - 将返回的 Twitter JSON 地理位置存储为变量

javascript - 使用 php 和 mysql 表单上的多个搜索字段

c# - 在 C# ASP.NET 中获取完整的查询字符串

html - Qt:让QWebview返回一个完整的URL

电话调用的 URL 方案