php 路径和url有什么区别
展开全部
#测试网址: http://localhost/blog/testurl.php?id=5
//获取域名或<a href="https://www.baidu.com/s?wd=%E4%B8%BB%E6%9C%BA%E5%9C%B0%E5%9D%80&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLm1R3PvDznH63PH0snW7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" class="baidu-highlight">主机地址</a>
echo $_SERVER['HTTP_HOST'].""; #localhost
//获取网页地址
echo $_SERVER['PHP_SELF'].""; #/blog/testurl.php
//获取网址参数
echo $_SERVER["QUERY_STRING"].""; #id=5
//获取<a href="https://www.baidu.com/s?wd=%E7%94%A8%E6%88%B7%E4%BB%A3%E7%90%86&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLm1R3PvDznH63PH0snW7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" class="baidu-highlight">用户代理</a>
echo $_SERVER['<a href="https://www.baidu.com/s?wd=HTTP_REFERER&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLm1R3PvDznH63PH0snW7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" class="baidu-highlight">HTTP_REFERER</a>']."";
//获取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5
//包含端口号的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://localhost:80/blog/testurl.php?id=5
//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
#http://localhost/blog
//获取域名或<a href="https://www.baidu.com/s?wd=%E4%B8%BB%E6%9C%BA%E5%9C%B0%E5%9D%80&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLm1R3PvDznH63PH0snW7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" class="baidu-highlight">主机地址</a>
echo $_SERVER['HTTP_HOST'].""; #localhost
//获取网页地址
echo $_SERVER['PHP_SELF'].""; #/blog/testurl.php
//获取网址参数
echo $_SERVER["QUERY_STRING"].""; #id=5
//获取<a href="https://www.baidu.com/s?wd=%E7%94%A8%E6%88%B7%E4%BB%A3%E7%90%86&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLm1R3PvDznH63PH0snW7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" class="baidu-highlight">用户代理</a>
echo $_SERVER['<a href="https://www.baidu.com/s?wd=HTTP_REFERER&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLm1R3PvDznH63PH0snW7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" class="baidu-highlight">HTTP_REFERER</a>']."";
//获取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5
//包含端口号的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://localhost:80/blog/testurl.php?id=5
//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
#http://localhost/blog
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询