php获取当前页面url地址,包括详细参数值等。
方法1:
复制代码 代码示例:
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);//注意编码
}
方法2:
复制代码 代码示例:
//获得当网址
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;
}
方法3(推荐):
复制代码 代码示例:
//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;
}