Home  >  Article  >  php教程  >  获取当前url(收集)

获取当前url(收集)

PHP中文网
PHP中文网Original
2016-05-25 17:10:58890browse

1. [代码][PHP]代码 

<?php
 // 说明:获取完整URL
 
function curPageURL() 
{
     $pageURL = &#39;http&#39;;
 
    if ($_SERVER["HTTPS"] == "on") 
    {
         $pageURL .= "s";
     }
     $pageURL .= "://";
 
    if ($_SERVER["SERVER_PORT"] != "80") 
    {
         $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
     } 
    else 
    {
         $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     }
     return $pageURL;
 }
 ?> 


     定义该函数之后就可以直接调用了:

2. [代码][PHP]代码  

<?php
 // 说明:获取无参数URL
 
function curPageURL() 
{
     $pageURL = &#39;http&#39;;
 
    if ($_SERVER["HTTPS"] == "on") 
    {
         $pageURL .= "s";
     }
     $pageURL .= "://";
 
    $this_page = $_SERVER["REQUEST_URI"];
     
    // 只取 ? 前面的内容
     if (strpos($this_page, "?") !== false) 
        $this_page = reset(explode("?", $this_page));
 
    if ($_SERVER["SERVER_PORT"] != "80") 
    {
         $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $this_page;
     } 
    else 
    {
         $pageURL .= $_SERVER["SERVER_NAME"] . $this_page;
     }
     return $pageURL;
 }
 ?>

3. [代码][PHP]代码    

<?php
 // 说明:获取无参数URL
 
function curPageURL() 
{
     $pageURL = &#39;http&#39;;
 
    if ($_SERVER["HTTPS"] == "on") 
    {
         $pageURL .= "s";
     }
     $pageURL .= "://";
 
    if ($_SERVER["SERVER_PORT"] != "80") 
    {
         $pageURL .= $_SERVER["SERVER_NAME"].":" . $_SERVER["SERVER_PORT"] . $_SERVER[&#39;PHP_SELF&#39;];
     } 
    else 
    {
         $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER[&#39;PHP_SELF&#39;];
     }
     return $pageURL;
 }
 ?>

4. [代码][PHP]代码 

<?php
 // 说明:获取 _SERVER[&#39;REQUEST_URI&#39;] 值的通用解决方案
 // 来源:drupal-5.1 bootstrap.inc
 // 整理:http://www.php.cn/
 
function request_uri()
 {
     if (isset($_SERVER[&#39;REQUEST_URI&#39;]))
     {
         $uri = $_SERVER[&#39;REQUEST_URI&#39;]; 
    }
     else
     {
         if (isset($_SERVER[&#39;argv&#39;]))
         {
             $uri = $_SERVER[&#39;PHP_SELF&#39;] .&#39;?&#39;. $_SERVER[&#39;argv&#39;][0];
         }
         else
         {
             $uri = $_SERVER[&#39;PHP_SELF&#39;] .&#39;?&#39;. $_SERVER[&#39;QUERY_STRING&#39;];
         }
     }
     return $uri;
 }
 ?>

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn