tags:

views:

97

answers:

4

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 :)

Here is one resource.

Also, you can find a host of free scrips out there.

Sarfraz
+1  A: 

A couple of examples

http://www.phpwhois.com/

http://www.nott.org/blog/php-whois-script.html

Jonathan
Also great examples +1 tyvm
H4cKL0rD
+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
Thank you for this also I'll need this +1 for getting involved intensly
H4cKL0rD
+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.