PHP获取当前用户真实IP的方法

WBOY
Release: 2016-06-20 13:02:48
Original
945 people have browsed it

近日做个项目跟Discuz有关,发现里面有很多东西写的非常不错呢,于是乎想着将里面的一些比较实用的功能提取出来和大家分享一下!毕竟Discuz里面的东东应该还算是非常不错的,比网上东找西找的那些信息要靠谱些吧!下面就分享一个利用PHP获取当前用户真实的IP地址的方法。

<p>function getIp(){</p>	$onlineip='';<br />	if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')){<br />		$onlineip=getenv('HTTP_CLIENT_IP');<br />	} elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')){<br />		$onlineip=getenv('HTTP_X_FORWARDED_FOR');<br />	} elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown')){<br />		$onlineip=getenv('REMOTE_ADDR');<br />	} elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')){<br />		$onlineip=$_SERVER['REMOTE_ADDR'];<br />	}<br />	return $onlineip;<br /><p>}
Copy after login



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!