I want to get the location of people logging into my website and I think it is called Whois. So how would I go about locating people in PHP?
+3
A:
Get their IP using:
$_SERVER['REMOTE_ADDR']
and get a free database to convert ip to location :)
Also, you can find a host of free scrips out there.
Sarfraz
2010-02-18 03:41:42
Also great examples +1 tyvm
H4cKL0rD
2010-02-18 03:43:36
+1
A:
You'll want to consider users behind proxies, as $_SERVER['REMOTE_ADDR'] may return the wrong IP address in that context. Check $_SERVER['HTTP_X_FORWARDED_FOR'] first to guard against this.
function getIpAddress() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $_SERVER['REMOTE_ADDR'];
}
Owen
2010-02-18 03:51:47
Thank you for this also I'll need this +1 for getting involved intensly
H4cKL0rD
2010-02-18 04:00:08
+1
A:
you dont need to do whois. you need to grab their IP address and map it to a location. here's how you get the IP address
$_SERVER['REMOTE_ADDR']
Google provides free IP Address to location services. whenever you use google jsapi script google automatically populates the google.loader.ClientLocation which has all the juicy details you need.