php获取url地址或参数

来源:https://www.sucaihuo.com/php/1237.html 2017-01-13 12:00浏览(2141) 收藏

本文演示了6种不同的url链接形式,在项目中经常遇到变量去定义,特别是最后一个会经常遇到,有些框架兼容性不是很好,特别是thinkphp的__APP__常量,在linux服务器不兼容,你可以重新定义它的方法。
php获取url地址或参数
分类:PHP > 其他 难易:初级
下载资源 下载积分: 30 积分
header("Content-type: text/html; charset=utf-8");
echo "<strong style='font-size:20px;color:red'>以http://www.sucaihuo.com/jquery/1237/demo/?id=100为例</strong><br>";

echo "当前域名:" . $_SERVER['HTTP_HOST'] . "<br>"; #http://www.sucaihuo.com

echo "当前绝对路径地址:" . $_SERVER['PHP_SELF'] . "<br>"; #/jquery/1237/demo/index.php

echo "网址参数:" . $_SERVER["QUERY_STRING"] . "<br>"; #id=100

echo '完整的url:http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "<br>"; #http://www.sucaihuo.com/jquery/1237/demo/?id=100

echo '包含端口号的完整url:http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"] . "<br>"; #http://www.sucaihuo.com:80/jquery/1237/demo/?id=100

$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"];
echo "当前url路径:" . dirname($url); #http://www.sucaihuo.com/jquery/1237/demo
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2