Hi guys, I'm a bit of a PHP noob so I'm sorry if this is a silly question. I was just wondering, I have a site that I have an affiliate store on..The product pages are php. Now most of my users are from the U.S (70%) but I do have users from the U.K too. I was wondering if there was a code or script I could get that would Geo-Target my page depending on who landed on it? Basically it would be as simple as "show code 1 if the visitor is from the U.S (or rest of the world)" and "show code 2 if the visitor is from the U.K" Or would it be possible to have a script like this made? I imagine it would be pretty simple? What do you guys think. Possible or not? Thanks a lot
I don't think there is any built-in function as such to gather information based on IP in PHP. However, there are web service apis which will allow you to do this for free. For instance, the following code will return the country: <?php $country = ''; $IP = $_SERVER['REMOTE_ADDR']; if (!empty($IP)) { $country = file_get_contents('http://api.hostip.info/country.php?ip='.$IP); } ?> Excerpted from: http://www.daniweb.com/forums/thread77998.html
Try this: http://www.maxmind.com/app/ip-location There are apache modules which you can get, and when its all set up, you can easily use php to pull out the relevant information. They even do a free lite version which should probably be enough!