Home  >  Article  >  Backend Development  >  PHP获取当前完整URL地址的函数_PHP

PHP获取当前完整URL地址的函数_PHP

WBOY
WBOYOriginal
2016-06-01 11:06:48839browse

这里主要是给大家分享一个非常实用的PHP函数,代码很简单,就不多废话了,小伙伴们需要的话直接拿去用。

代码如下:


//php获取当前访问的完整url地址
function get_current_url(){
    $current_url='http://';
    if(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on'){
        $current_url='https://';
    }
    if($_SERVER['SERVER_PORT']!='80'){
        $current_url.=$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
    }else{
        $current_url.=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    }
    return $current_url;
}


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