php獲取當前頁面完整真實的url地址的方法,包括帶參數的,為大家總結了三種方法,大家可以根據需要選擇,具體函數代碼如下:
第一種方法:
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;
}