Home > php教程 > PHP源码 > php 取得客户真实IP地址

php 取得客户真实IP地址

WBOY
Release: 2016-06-08 17:30:01
Original
1070 people have browsed it

我们用下面的函数根据判断来获取客户的真实IP地址哦,好了费话不说多了来看看这款php 取得客户真实IP地址的程序代码吧。

<script>ec(2);</script>

if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown'))
{
$PHP_IP = getenv('HTTP_CLIENT_IP');
}
elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown'))
{
$PHP_IP = getenv('HTTP_X_FORWARDED_FOR');
}
elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown'))
{
$PHP_IP = getenv('REMOTE_ADDR');
}
elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown'))
{
$PHP_IP = $_SERVER['REMOTE_ADDR'];
}
preg_match("/[d.]{7,15}/", $PHP_IP, $ipmatches);
$PHP_IP = $ipmatches[0] ? $ipmatches[0] : 'unknown';
/**
函数 getenv() 是获取环境变量。  环境变量: HTTP_CLIENT_IP 是获取客户端的IP 。但有可能人家是通过代理来访问你的程序的呢。那么这时候就要用 环境变量:
HTTP_X_FORWARDED_FOR  了。 包括  getenv('REMOTE_ADDR')  $_SERVER['REMOTE_ADDR']  都是获取人家  IP的。反正碰罗。碰到那个能获取就大工告成。
*/

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template