php - 在 PHP 中获取带有查询字符串的当前 URL 路径

标签 php url

我需要从当前请求的 URL 中获取路径。例如,如果当前 URL 是:

"http://www.example.com/example/test/hi.php?randomvariable=1"

我想要这个:

"/example/test/hi.php?randomvariable=1"

最佳答案

你想要 $_SERVER['REQUEST_URI']。来自 the docs :

'REQUEST_URI'

The URI which was given in order to access this page; for instance, '/index.html'.

关于php - 在 PHP 中获取带有查询字符串的当前 URL 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16198790/

相关文章:

php - MySQL 查询根据 ID 连接所有字段以获取 facebook 之类的通知

php - SilverStripe 4.3.1 - 从 SS 4.2.1 将默认 bool 值转换为是或否

php - 如何使用繁荣库的 fRecordSet 构建方法与预览交互并保存?

python - 如何在GAE中设置动态URL?

javascript - 使用 Cheerio 和用于网页抓取的 url 执行与 document.getElementsByClassName() 相同的操作

codeigniter - CodeIgniter 中的 URL 重写

php - Laravel orderBy 排序不正确

php - php (wordpress) 中的动态图像链接

php - 帮助破解 Gruber 的自由 URL 正则表达式

url - 为什么我的背景图像没有显示在我的 github.io 上?