php 获取url

Posted on Posted in php
Tips: 本文创建于2015年11月26日,已超过 2 年,内容或图片可能已经失效!

php 获取当前url

  1. <?php  
  2. //获取域名或主机地址   
  3. echo $_SERVER['HTTP_HOST']."<br>"; #/office/url.php  
  4. //获取网页地址   
  5. echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php  
  6. //获取网址参数   
  7. echo $_SERVER["QUERY_STRING"]."<br>"; #id=100  
  8. //获取完整的url  
  9. echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."<br>";      
  10. echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."<br>";  
  11. #http://localhost/office/url.php?id=100  
  12.   
  13. //包含端口号的完整url  
  14. echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br>";   
  15. #http://localhost:80/office/url.php?id=100  
  16. //只取路径  
  17. $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."<br>";   
  18. echo dirname($url);  
  19. #http://localhost/office  
» 转载请注明来源:若我若鱼 » php 获取url

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + 9 =