请求PHP中没有GET参数的字符串 [英] Request string without GET arguments in PHP

查看:92
本文介绍了请求PHP中没有GET参数的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法来获取没有GET参数的请求文件或目录?例如,如果URL是 http://mysite.com/directory/file.php?paramater=value 我想只返回 http ://mysite.com/directory/file.php 。我很惊讶在 $ _ SERVER [] 中没有简单的索引。我错过了吗?谢谢!

Is there a simple way to get the requested file or directory without the GET arguments? For example, if the URL is http://mysite.com/directory/file.php?paramater=value I would like to return just http://mysite.com/directory/file.php. I was surprised that there is not a simple index in $_SERVER[]. Did I miss one? Thanks!

推荐答案

您可以使用 $ _ SERVER ['REQUEST_URI'] 获取请求的路径。然后,你需要删除参数......

You can use $_SERVER['REQUEST_URI'] to get requested path. Then, you'll need to remove the parameters...

$uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);

然后,添加主机名和协议。

Then, add in the hostname and protocol.

echo 'http://' . $_SERVER['HTTP_HOST'] . $uri_parts[0];

请注意,如果混合,您还必须检测协议http: https:// 。我作为练习留给你。

Note that you'll have to detect protocol as well, if you mix http: and https://. That I leave as an exercise for you.

这篇关于请求PHP中没有GET参数的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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