开发者

Cannot access visitor's ip address in php

开发者 https://www.devze.com 2023-01-16 19:21 出处:网络
i am trying to store ip addresses of people who are visiting my web site. For that i use the below given code.

i am trying to store ip addresses of people who are visiting my web site. For that i use the below given code.

$serverIP=$_SERVER['REMOTE_ADDR'];

but instead of getting an IP like 112.200.xxx.xxx (when i visit), i got 192.9.200.195开发者_JAVA技巧..

somebody please help me

thanks in advance

tismon


try this, maybe its a proxy(?)

if ($_SERVER['HTTP_X_FORWARDED_FOR'])
{
  $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
  $ip = $_SERVER['REMOTE_ADDR'];
} 
echo $ip;


looks like you're thinking 192.9.200.195 is a local ip-adress - but its not, local adresses you mean are starting with 192.168.. 192.9.200.195 looks ok to me, if it's not, please try to explain you problem more detailed.


try

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
echo getRealIpAddr();


You can also try this:

<?php
$var = file_get_contents('http://www.whatismyip.com/automation/n09230945.asp');
print $var;
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消