Home > php教程 > PHP源码 > body text

获取当前url(收集)

PHP中文网
Release: 2016-05-25 17:10:58
Original
963 people have browsed it

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;
 }
 ?> 


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

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;
 }
 ?>
Copy after login

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;
 }
 ?>
Copy after login

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;
 }
 ?>
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template