Heim  >  Artikel  >  Backend-Entwicklung  >  php获取当前页面url地址及参数_PHP教程

php获取当前页面url地址及参数_PHP教程

WBOY
WBOYOriginal
2016-07-13 16:54:49976Durchsuche

php获取当前页面url地址及参数 要获取当前页面的完整地址我们要经过很多操作如HTTP或HTTPS php文件与路径 主机域名 查询参数最后就成了。 获取协议 - HTTP

php教程获取当前页面url地址及参数
要获取当前页面的完整地址我们要经过很多操作如http或https教程  php文件与路径 主机域名 查询参数最后就成了。
获取协议 - http
url的协议,可以读出在$ _server ['server_protocol']变量。
*/

echo $_server['server_protocol'];

/*
如果你检查值,可以发现,不只是http或https,但这样的字符串:http/1.1的

*/

$protocol = strpos(strtolower($_server['server_protocol']),'https')  === false ? 'http' : 'https';

/*
获取主机域名*/

$host = $_server['http_host'];

/*
利用$ _server['script_name']获取除域名外的php文件与路径

*/

$script = $_server['script_name'];


//获取?后面查询参数

$params = $_server['query_string'];


//方法二
$uri = $_server['request_uri'];

//下面来看一个完整的获取当前url实例

$protocol = strpos(strtolower($_server['server_protocol']),'https')   === false ? 'http' : 'https';
$host     = $_server['http_host'];
$script   = $_server['script_name'];
$params   = $_server['query_string'];
$currenturl = $protocol . '://' . $host . $script . '?' . $params;
echo $currenturl;

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/631733.htmlTechArticlephp获取当前页面url地址及参数要获取当前页面的完整地址我们要经过很多操作如HTTP或HTTPS php文件与路径 主机域名 查询参数最后就成了。获...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn