Detecting user location - PHP/jQuery

All about creating websites!
Post Reply
User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Detecting user location - PHP/jQuery

Post by z3r0aCc3Ss »

Holla fellas...

Is there any way to accurately detect user location?
For example, I am in the country 'C', in state 'S', in the city 'X'. So, my user location should be of city 'X'.

Current situation:
In my current project, I want to redirect users to different websites based on their Geo-location. For this reason, I have bought DB of ip2location.com, for $499.
http://www.ip2location.com/databases/db ... de-zipcode
I am detecting user location from his IP, like this:

Code: Select all

function get_client_ip() {
	$ipaddress = '';
	if (getenv('HTTP_CLIENT_IP'))
		$ipaddress = getenv('HTTP_CLIENT_IP');
	else if (getenv('HTTP_X_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
	else if (getenv('HTTP_X_FORWARDED'))
		$ipaddress = getenv('HTTP_X_FORWARDED');
	else if (getenv('HTTP_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_FORWARDED_FOR');
	else if (getenv('HTTP_FORWARDED'))
		$ipaddress = getenv('HTTP_FORWARDED');
	else if (getenv('REMOTE_ADDR'))
		$ipaddress = getenv('REMOTE_ADDR');
	else
		$ipaddress = 'UNKNOWN';
	return $ipaddress;
}
But, this doesn't gives me correct location. What if I am in city 'X', and have an IP address which is actually located in city 'Y'?
What is the most accurate way of detecting user location? I don't even mind purchasing an API if it's giving me correct result.
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Detecting user location - PHP/jQuery

Post by ayu »

First of all you should remove all methods except the "$ipaddress = getenv('REMOTE_ADDR');" method.
All other methods can be easily modified by the client via headers and should never be trusted.

IP can only give you information about the ISP really and will never pinpoint the exact city.
If you need more precise positioning then you need to ask the user for permission.

Code: Select all

http://www.w3schools.com/html/html5_geolocation.asp
Hope this answers your question :)
"The best place to hide a tree, is in a forest"

User avatar
z3r0aCc3Ss
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 700
Joined: 23 Jun 2009, 16:00
14
Contact:

Re: Detecting user location - PHP/jQuery

Post by z3r0aCc3Ss »

Yup, absolutely.
Thanks for the help. :)
Beta tester for major RATs, all kinds of stealers and keyloggers.
Learning NMAP

Post Reply