search
Homephp教程PHP源码获取当前url(收集)

获取当前url(收集)

May 25, 2016 pm 05:10 PM
php

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft