|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| 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
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
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 |
|
|||
|
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 Code:
$put_in_db = "INSERT INTO your_table (id, user_ip, date) VALUES ('', '$REMOTE_ADDR', NOW())";
$put_in_res = mysql_query($put_in_db);
|
|
|||
|
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 |
|
|||
|
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;
}
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |