Hi guys, Looking for some kind of method to display pieces of website content to users from specific countries only. I'd like to display a hover ad to users coming from the US when they login to their account. I looked at Maxmind GeoIP, but don't really get it.. Any ideas would be greatly appreciated.
You need to grab the visitors IP address: $_SERVER['REMOTE_ADDR'] Validate this IP Address with a IP to country Database. They are some free ones available over the internet or some offer API for this. You can use an if/else statement to show/hide the content from the specific visitor.
yeah.. i vote for IPGeolocation, they service is very awesome i has used them for a few month, so far everything is ok
I do not think redirecting people according to their ip is a very good solution. try to find another solution. i live in UK and at work all our computers got IP addresses for Belgium. Everytime i try to watch something on bbc it is saying i am not allowed because i am not in UK.
Baris, it's not "relocating", it's simply showing people country targetted offers. A few that are inaccurate won't be to much of a problem. Thanks for the input guys.
I just posted this in another thread... There is a site you can go to to get a free script that can get you all sorts of info on an IP including country, country code, state/region... the site is http://geoplugin.com You can use this to do it... Get the plugin.class script, and... <? $ip=$_SERVER['REMOTE_ADDR']; require_once('geoplugin.class.php'); // check country $geoplugin = new geoPlugin(); $geoplugin->locate($ip); $hitfrom=$geoplugin->countryCode; if ($hitfrom=="US"){ //shows content to US... } else if ($hitfrom=="CA"){ // shows content to Canada... } ?> PHP: