標籤:使用者 fun UNC 擷取網頁 案例 根據 head 主機地址 連接埠
//擷取網域名稱或主機地址
echo $_SERVER['HTTP_HOST']."<br>"; #jiqing.nikon.com
//擷取網頁地址
echo $_SERVER['PHP_SELF']."<br>"; #/Home/picture
//擷取網址參數
echo $_SERVER["QUERY_STRING"]."<br>"; #machine_type_id=2
//擷取使用者代理程式
echo $_SERVER['HTTP_REFERER']."<br>"; #http://jiqing.nikon.com/index.php/Home/index
//擷取完整的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
//包含連接埠號碼的完整url
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
//只取路徑
echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."<br>"; # http://jiqing.nikon.com/index.php/Home
應用案例,根據瀏覽器類型,自動切換
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擷取路徑