• php获取网址


     1 #测试网址:     http://localhost/blog/testurl.php?id=5
     2 
     3 //获取域名或主机地址 
     4 echo $_SERVER['HTTP_HOST']."<br>"; #localhost
     5 
     6 //获取网页地址 
     7 echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php
     8 
     9 //获取网址参数 
    10 echo $_SERVER["QUERY_STRING"]."<br>"; #id=5
    11 
    12 //获取用户代理 
    13 echo $_SERVER['HTTP_REFERER']."<br>"; 
    14 
    15 //获取完整的url
    16 echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    17 echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
    18 #http://localhost/blog/testurl.php?id=5
    19 
    20 //包含端口号的完整url
    21 echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
    22 #http://localhost:80/blog/testurl.php?id=5
    23 
    24 //只取路径
    25 $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; 
    26 echo dirname($url);
    27 #http://localhost/blog
  • 相关阅读:
    qsort
    strcmp
    LotteryDrawing
    retire or not retire ? is a question.
    alloc && afree
    strlen
    c point
    c point ccccc
    MySQL MGR源码分析2
    MySQL MGR实现分析
  • 原文地址:https://www.cnblogs.com/endv/p/8573405.html
Copyright © 2020-2023  润新知