views:

84

answers:

4

Hi,

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..

somebody please help me

thanks in advance

tismon

+3  A: 

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;
Sebastian Brózda
+1  A: 

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();
Yogesh
that is also showing the same ip starting with 192.9. when i visit whatismyip.com, it shows a diff ip starting with 112.200.
tismon
+2  A: 

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.

oezi
@oezi yep, i think 192.9.200.195 is my local ip. when i visit whatismyip.com, it shows a diff ip starting with 112.200. should i change anything in php.ini ?
tismon
@tismon: as said, it's not your local ip (or: this shouldn't be your local ip as that would mean you network is set up totaly wrong) - maybe the 112.200... is saved in one of the other variables posted by yogesh (but i don't think so). do you use any of this "i wanna be annonymous in the internet, so hide my ip"-programs?
oezi
A: 

you can also try

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