本文實例講述了php獲取客戶端IP及URL的方法。分享給大家供大家參考,具體如下:
代碼如下復制代碼functiongetonlineip(){//獲取用戶ip
if($_SERVER['HTTP_CLIENT_IP'])
{
$onlineip=$_SERVER['HTTP_CLIENT_IP'];//用戶IP
}
elseif($_SERVER['HTTP_X_FORWARDED_FOR'])
{
$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];//代理IP
}
else
{
$onlineip=$_SERVER['REMOTE_ADDR'];//服務器IP
}
return$onlineip;
}
functioncurPageURL()//獲取完整的url
{
$pageURL='http'
if($_SERVER["HTTPS"] =="on")
{
$pageURL.="s";
}
$pageURL.="://";
if($_SERVER["SERVER_PORT"] !="80")
{
$pageURL.=$_SERVER["SERVER_NAME"] .":".$_SERVER["SERVER_PORT"] .$_SERVER["REQUEST_URI"];
}
else
{
$pageURL.=$_SERVER["SERVER_NAME"] .$_SERVER["REQUEST_URI"];
}
return$pageURL;
}