php获取客户端ip地址
发布时间:2016-10-27 编辑:jiaochengji.com
教程集为您提供php获取客户端ip地址等资源,欢迎您收藏本站,我们将为您提供最新的php获取客户端ip地址资源
本教程提供几款获取IP地址的代码,各有各的优点,这里获取用户ip 是利用php的全局变量实现的,下面来看看有没有你要找的。
//最简单的方法
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5633')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5633>$ip = $_server["remote_addr"];echo $ip;
//最实用获取用户ip地址代码
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4270')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4270>function get_real_ip() {$ip=false;
if(!empty($_server["http_client_ip"]))
{
$ip = $_server["http_client_ip"];
}
if (!empty($_server['http_x_forwarded_for']))
{
$ips教程 = explode (", ", $_server['http_x_forwarded_for']);
if ($ip) {
array_unshift($ips, $ip);
$ip = false;
}
for ($i = 0; $i < count($ips); $i )
{
if (!eregi ("^(10|172.16|192.168).", $ips[$i]))
{
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_server['remote_addr']);
}
echo get_real_ip();
//获取ip地址与端口号
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4399')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4399>$ip =$_server["remote_addr"];$port = $_server['remote_port'];
echo $ip.$port;
//有一点意思
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9069')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9069>if(getenv('http_client_ip')){
$onlineip = getenv('http_client_ip');
}
elseif(getenv('http_x_forwarded_for'))
{
$onlineip = getenv('http_x_forwarded_for');
}
elseif(getenv('remote_addr'))
{
$onlineip = getenv('remote_addr');
}
else
{
$onlineip = $http_server_vars['remote_addr'];
}
echo $onlineip;
echo "
";
//利用qq接口
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5245')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy5245>function get_ip_place(){$ip=file_get_contents("http://fw.qq.com/ipaddress");
$ip=str_replace('"',' ',$ip);
$ip2=explode("(",$ip);
$a=substr($ip2[1],0,-2);
$b=explode(",",$a);
return $b;
}
$ip=get_ip_place();
print_r($ip);
您可能感兴趣的文章:
php获取远程客户端真实ip地址
php函数获取在线ip与客户端ip
php获取真实ip地址的实例分享
php 获取网站地址的函数代码
深入解析PHP获取客户端IP的方法
PHP通过IP获取地理位置的代码
php用静态类实现获取客户端IP地址的方法
php获取客户端ip地址的代码
获取用户真实IP地址的php代码
php无法获取真实ip
上一篇:session 教程二
下一篇:session全教程(二)
[关闭]