实验环境:
测试域名daxiangtravel.com,apache根目录/mnt/,测试目录/mnt/qa/test,测试文件名为index.PHP。
获取代码:
获取当前目录:
PHP;">
getcwd();
// /mnt/qa/test
dirname(__FILE__);
// /mnt/qa/test
获取域名或主机地址
PHP;">
$_SERVER['HTTP_HOST'];
//daxiangtravel.com
获取网页地址
获取网址参数
PHP;">
$_SERVER["QUERY_STRING"];
// v=433
获取用户代理
$_SERVER['HTTP_REFERER'];
// http://daxiangtravel.com/qa/test/index.PHP?v=433
获取完整的url
PHP;">
'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
只取路径
PHP;">
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
// http://daxiangtravel.com/qa/test
包含端口号的完整url
PHP;">
'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"]
.$_SERVER["REQUEST_URI"];
// http://daxiangtravel.com:80/qa/test/index.PHP?v=433
原文链接:https://www.f2er.com/php/17312.html