Get domain name or host address
echo $_SERVER['HTTP_HOST']."<br>"; #jiqing.nikon.com
Get web Address
echo $_SERVER['PHP_SELF']."<br>"; #/Home/picture
Get URL parameters
echo $_SERVER["QUERY_STRING"]."<br>"; #machine_type_id=2
Get user Agent
echo $_SERVER['HTTP_REFERER']."<br>"; #http://jiqing.nikon.com/index.php/Home/index
Get the full URL
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."<br>"; # http://jiqing.nikon.com/index.php/Home/picture?machine_type_id=2echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."<br>"; #http://jiqing.nikon.com/Home/picture?machine_type_id=2
Full URL with port number
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br>";#http://jiqing.nikon.com:80/index.php/Home/picture?machine_type_id=2
Fetch path only
echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."<br>"; # http://jiqing.nikon.com/index.php/Home
Application cases, automatic switching based on browser type
vendor('Func.Func');if (!Func::isMobile()) { // 跳转到手机端 if ($_SERVER['QUERY_STRING']) { header("location: /index.php".$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']); } else { header("location: /index.php".$_SERVER['PHP_SELF']); }}
PHP Get Path