Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how much info can you get out of IP address in php? 1

Status
Not open for further replies.

MAWarGod

Programmer
Feb 15, 2002
352
US
How do I get the country, state, city, latitude, longitude, ZIP code, and timezone in PHP from the IP address.

Now I guess My question here comes out of the hours I spent looking over the wed, for a free script I could maybe mod to fit my needs, or the many, many requests out there for a script like this..

Now as I said in my other thread I am a novice to php. So I am sure this question has been asked many times but in my search I only found it asked in a mail function.. I need to either include it to my signup script or have it input to the set db table..

Code:
$xIp='';
		$xIp= (!empty($_SERVER['REMOTE_ADDR']))?$_SERVER['REMOTE_ADDR'] :((!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR']: @getenv('REMOTE_ADDR'));
		if(isset($_SERVER['HTTP_CLIENT_IP']))
		$xIp=$_SERVER['HTTP_CLIENT_IP'];
		return htmlspecialchars($xIp,ENT_QUOTES);
	}
I am not sure it the is the right start but it the only one I could find..these are the strings variables in my input array..
Code:
$timezone
$county
$stateprovince
$city
$zip
$ziprec['latitude']
$ziprec['longitude']

do I use sessions??? Really the question is list long can someone please point me in the right direction.

Thank You
Robert


MA WarGod

I believe if someone can think it, it can be programmed
 
You have two choices, use a GeoIp service that can return the information you require or install and use the GeoIP extension for PHP.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Phil thank you very much awesome advice, I can even use smarty with it.. {$smarty.session.iplocation.city_name} within my tpl files, again thank you!!




I wish you well
Robert

MA WarGod

I believe if someone can think it, it can be programmed
 
Glad I could Help.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top