iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-21-2005, 04:18 PM
richkoi's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Atlanta, GA
Posts: 451
richkoi RepRank 0
Default PHP IP Address and City

Is there a function in PHP to display a user's city, state and ip address?

How about Javascript?

Is there a way to create a function to bounce that information back to a database? (kind of how a stat counter would do?)

Thanks,

Rich
__________________
Me
Reply With Quote
  #2 (permalink)  
Old 06-21-2005, 04:56 PM
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2004
Location: Austin, TX
Posts: 1,229
jestep RepRank 0
Default

No way to do City or State unless you have an IP location database system. These are out there but they are so big that it is usually a very slow process.

Here's the value for the IP in php.
Code:
$REMOTE_ADDR
Something like this would put each visitor in a database.
Code:
$put_in_db = "INSERT INTO your_table (id, user_ip, date) VALUES ('', '$REMOTE_ADDR', NOW())";
$put_in_res = mysql_query($put_in_db);
This would not display any output, so if there was an error your page would still function properly.
Reply With Quote
  #3 (permalink)  
Old 06-21-2005, 05:35 PM
WebProWorld MVP
WebProWorld MVP
 
Join Date: Jul 2004
Location: Omaha
Posts: 2,714
brian.mark RepRank 3brian.mark RepRank 3
Default We use...

We use http://www.maxmind.com/app/geoip_country the free country version from here. City and state was a paid service that we didn't see the need for at the moment, but they have it available for you if you truly need it here: http://www.maxmind.com/app/city. Price was $20/50,000 queries, or you can buy the data for $370 plus $90/month for updates. The $20 for 50,000 seems better to me, especially if you cache the data and only query new IP's.

They have a php module available here: http://www.maxmind.com/app/php for the country piece. The data is updated for free monthly.

We're currently using the country code to weed out orders from the countries we don't accept orders from. Seems to catch almost all of them.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #4 (permalink)  
Old 12-11-2008, 02:54 AM
WebProWorld New Member
 
Join Date: Dec 2008
Posts: 1
nobody RepRank 0
Default Re: PHP IP Address and City

Code:
function getLocationCaidaNetGeo($ip)
{ 
$NetGeoURL = "http://netgeo.caida.org/perl/netgeo.cgi?target=".$ip; 
 
if($NetGeoFP = fopen($NetGeoURL,r))
{ 
        ob_start();

        fpassthru($NetGeoFP);
         $NetGeoHTML = ob_get_contents();
         ob_end_clean();

 fclose($NetGeoFP);
 }
 preg_match ("/LAT:(.*)/i", $NetGeoHTML, $temp) or die("Could not find element LAT");
 $location[0] = $temp[1];
 preg_match ("/LONG:(.*)/i", $NetGeoHTML, $temp) or die("Could not find element LONG");
 $location[1] = $temp[1];

 return $location;
 }
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:48 PM.



Search Engine Optimization by vBSEO 3.3.0