Hi Friends,
I want to get the loggedin users’ location in php.
For ex: If a user access the site from Bangalore, t hen my function should return the location like Bangalore, india. Please help me how to get these information. I am trying to get the ip address.
I am using the code like this:
<?php
function getRealIpAddr()
{
echo “<pre>”;
print_r($_SERVER);
echo “</pre>”;
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 " ip address ".getRealIpAddr();
$ip=@$REMOTE_ADDR;
echo “<b>IP Address= $ip</b>”;
I am planning to try this with the help of ip address. But it provides ::1. But my IP Address : 14.96.16.59
Plz help me out
Thank u so much
Can you wrap your code in php tags so that it is readable?
It’s item 9 in the New to the Program Your Site forums? Please read this. sticky topic.
Let me guess… you read it but missed that bit
Hi Friends,
I want to get the loggedin users’ location in php.
For ex: If a user access the site from Bangalore, t hen my function should return the location like Bangalore, india. Please help me how to get these information. I am trying to get the ip address.
I am using the code like this:
<?php
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’]))
{
$ip=$_SERVER[‘HTTP_X_FORWARDED_FOR’];
}
else
{
$ip=$_SERVER[‘REMOTE_ADDR’];
}
return $ip;
}
echo " ip address ".getRealIpAddr();
$ip=@$REMOTE_ADDR;
echo “<b>IP Address= $ip</b>”;
?>
I am planning to try this with the help of ip address. But it provides ::1. But my IP Address : 14.96.16.59
Plz help me out.
Thank u so much
This will useful to solve your problem, but it is a trail version;
Please go through this;
http://www.ipaddressapi.com/
Just use “$_SERVER['REMOTE_ADDR'];
” not all the other useless code.
Otherwise you will just cause yourself grief down the road.
Forther more, if you are doing this on a development machine and the server resides on the same machine and is access using localhost or 127.0.0.1, then the IP will be 127.0.0.1 or ::1 (IPv6 equivalent).
I repeat, only use “$_SERVER['REMOTE_ADDR'];
” everything else is untrusted/unreliable.