PHP获取当前页面URL路径

PHP获取当前页面URL路径,第1张

概述#测试网址:http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST'].""; #localhost //获取网页地址 echo $_SERVER['PHP_SELF'].""; #/blog/testurl.php //获取网址参数 echo $_SERVER["QUER

#测试网址: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=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLnhm1PWT1uH-9uwfzPhFh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGcpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" >主机地址</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=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLnhm1PWT1uH-9uwfzPhFh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGcpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" >用户代理</a> echo $_SERVER['<a href="https://www.baIDu.com/s?wd=http_REFERER&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YLnhm1PWT1uH-9uwfzPhFh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGcpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHmsPHfsPWTknHc1PWmYnjnYPs" target="_blank" >http_REFERER</a>']."";  //获取完整的urlecho '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 //包含端口号的完整urlecho '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


总结

以上是内存溢出为你收集整理的PHP获取当前页面URL路径全部内容,希望文章能够帮你解决PHP获取当前页面URL路径所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1014818.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存