时间:2021-07-01 10:21:17 帮助过:8人阅读
第一种方法:
function GetCurUrl(){
if(isset($_SERVER['REQUEST_URI'])){
$url=$_SERVER['REQUEST_URI'];
}else{
if(isset($_SERVER['argv'])){
$url=$_SERVER['PHP_SELF'].'?'.$_SERVER['argv'][0];
}else{
$url=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
}
}
return urlencode($url);//注意这里给编码了}
第二种方法(据说织梦用的就是这种方法):
//获得当前的脚本网址
function GetCurUrl(){
if(!empty($_SERVER['REQUEST_URI'])){
$scriptName=$_SERVER['REQUEST_URI'];
$nowurl=$scriptName;
}else{
$scriptName=$_SERVER['PHP_SELF'];
if(empty($_SERVER['QUERY_STRING'])){
$nowurl=$scriptName;
}else{
$nowurl=$scriptName.'?'.$_SERVER['QUERY_STRING'];
}
}
return $nowurl;}
第三种方法(推荐):
//php获取当前访问的完整url地址
function GetCurUrl(){
$url='http://';
if(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on'){
$url='https://';
}
if($_SERVER['SERVER_PORT']!='80'){
$url.=$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
}else{
$url.=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
return $url;
}