首頁 >後端開發 >php教程 >PHP获取当前用户真实的IP

PHP获取当前用户真实的IP

WBOY
WBOY原創
2016-06-23 13:24:501065瀏覽

function getIp(){$onlineip='';if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')){$onlineip=getenv('HTTP_CLIENT_IP');} elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')){$onlineip=getenv('HTTP_X_FORWARDED_FOR');} elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown')){$onlineip=getenv('REMOTE_ADDR');} elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')){$onlineip=$_SERVER['REMOTE_ADDR'];}return $onlineip;}

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn