實驗環(huán)境:
測試域名daxiangtravel.com族奢,apache根目錄/mnt/姥闭,測試目錄/mnt/qa/test,測試文件名為index.php越走。
獲取代碼:
獲取當前目錄:
getcwd();
// /mnt/qa/test
dirname(__FILE__);
// /mnt/qa/test
獲取域名或主機地址
$_SERVER['HTTP_HOST'];
//daxiangtravel.com
獲取網(wǎng)頁地址
$_SERVER['PHP_SELF'];
// /qa/test/index.php
獲取網(wǎng)址參數(shù)
$_SERVER["QUERY_STRING"];
// v=433
獲取用戶代理
$_SERVER['HTTP_REFERER'];
// http://daxiangtravel.com/qa/test/index.php?v=433
獲取完整的url
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// http://daxiangtravel.com/qa/test/index.php?v=433
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
// http://daxiangtravel.com/qa/test/index.php?v=433
只取路徑
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
// http://daxiangtravel.com/qa/test
包含端口號的完整url
'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"]
.$_SERVER["REQUEST_URI"];
// http://daxiangtravel.com:80/qa/test/index.php?v=433