首页 >后端开发 >php教程 >PHP获取当前用户真实的IP

PHP获取当前用户真实的IP

WBOY
WBOY原创
2016-06-23 13:24:501064浏览

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