php获取当前页面完整真实的url地址的方法,包括带参数的,总结了三种方法,大家可以根据需要选择,具体函数代码如下:
第一种方法:
<p>function GetCurUrl(){</p> if(isset($_SERVER['REQUEST_URI'])){<br /> $url=$_SERVER['REQUEST_URI'];<br /> }else{<br /> if(isset($_SERVER['argv'])){<br /> $url=$_SERVER['PHP_SELF'].'?'.$_SERVER['argv'][0];<br /> }else{<br /> $url=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];<br /> }<br /> }<br /> return urlencode($url);//注意这里给编码了<br /><p>}</p>
第二种方法(据说织梦用的就是这种方法):
<p>//获得当前的脚本网址</p>function GetCurUrl(){<br /> if(!empty($_SERVER['REQUEST_URI'])){<br /> $scriptName=$_SERVER['REQUEST_URI'];<br /> $nowurl=$scriptName;<br /> }else{<br /> $scriptName=$_SERVER['PHP_SELF'];<br /> if(empty($_SERVER['QUERY_STRING'])){<br /> $nowurl=$scriptName;<br /> }else{<br /> $nowurl=$scriptName.'?'.$_SERVER['QUERY_STRING'];<br /> }<br /> }<br /> return $nowurl;<br /><p>}</p>
第三种方法(推荐):
<p>//php获取当前访问的完整url地址</p>function GetCurUrl(){<br /> $url='http://';<br /> if(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on'){<br /> $url='https://';<br /> }<br /> if($_SERVER['SERVER_PORT']!='80'){<br /> $url.=$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];<br /> }else{<br /> $url.=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];<br /> }<br /> return $url;<br />}