PHP获取当前完整URL地址的函数_php技巧
程序员文章站
2022-05-28 17:53:22
...
这里主要是给大家分享一个非常实用的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;
}
复制代码 代码如下:
//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;
}