Ok first I'm reasonably new to php. So there might be better ways of doing this. Geo targetting can be very cool. I'm in the UK, and only people in the UK would ever buy my products/services. Therefore all other visitors are useless to me. So I do one of two things depends on the site. IF they're outside the UK I might display big adsense banners at the top of every page. Or I might forward them onto a USA site (in exchange for the USA site sending their UK visitors back to me) <? # Geotargetting script by TFMG on digitalpoint forums http://forums.digitalpoint.com if(!($ip = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) $ip = $HTTP_SERVER_VARS['REMOTE_ADDR']; $agent = $_SERVER['HTTP_USER_AGENT']; $location = file_get_contents("http://www.hostip.info/api/get.html?ip=$ip"); if (!eregi('googlebot', $agent) || !eregi('msnbot', $agent) || !eregi('slurp', $agent)) { if (!eregi('UNITED KINGDOM', $location)) { // do something // like display google adsense // or send the user to a USA partner website.... } } ?> Code (markup): Let me break the above down to make it easier for people. The first two lines get the IP address of the visitor. The third line gets the users USERAGENT. This helps determine if the visitor is a human or a robot, and what browser they're using etc. This statement says. If the person visiting is not googlebot, msnbot or yahoobot then excute the contents of the braces {} (If it's a search engine we don't want to mess around with what they see...) Finally If they're NOT from the United Kingdom then execute the contents of the braces {}. Now, the contents of the braces could be.... 1. A meta refresh to another site in the visitors geographic area OR 2. Some banners/adsense etc. I really hope this helps. I've got loads of other neat little scripts....and depending on the response to this I'll take the time to get them posted. Feedback appreciated.
Exactly what I do as well. Due to great international ranking I get 'useless' traffic. Am indeed plastering AdSense on their screens or serving US/Other related affiliate links instead to monetize on the traffic. I use a database though instead of a 3d party lookup. To take it easy on the database requests I have a bit of code that checks the referer. It basically only checks their IP if the referer is g.com or other .com/non-UK SE. If so then it will do the geotargeting. If referer is OK then just assume UK visitor without the IP checks. Good post, I might rate it
Someone as clever as me! I thought about that, but are databases not expensive? Surely a US visitor could come to your site from a UK click through....? Therefore you could miss out? Or did I miss something? WOO!
Oh one last thing, If you Somewhere in the script it will show you the country where you're visiting from....so if you need to tweak the script (you might not be in the UK) then that might help you. And if you decide to use the script pm me and give me a link to one of my sites, please. I wont cry if you don't but I could do with a couple of links
Fantastic. I've been wondering about that for a while. One of our shops only ships to the UK (at the suppliers request). I was working out how to send the visitor to a stockist in their own country (via an affiliate link, natch ). This'll do the trick nicely. Of course, I won't just redirect them away automatically. Someone abroad might be buying a gift for someone in the UK. Plus, on my old ISP (NDO) I was often accused of being in the states by some site's geotargetting... and skynews wouldn't let me in! Gah! Cheers again TFMG. Chris
For my own purposes I have written a little addition. It tells the user they're being directed in 10 seconds and they have the choice not to, if they decide not too then I've set a cookie, so in future they don't get hassled out
Yeah, good idea. I think I'll just add a strapline at the top of each page that is "switched on" by geotargeting. This can then directing them to an international page to choose at will. (or they can shut it up with a cookie if they want). Cheers Chris
Thank you very much for this neat script! Users that actually buy things on my sites are people whose mother tongue is English. How would could your script redirect people not from ie. England, USA, Ireland, NZ, ... ? I doubt simply adding the country name will do the trick.. Thank you.
First let me understand the question. So you want to redirect all english speaking countries to one place, then everyone else to another?
I think this may be considered as cloaking your content... Having had my site banned by the big G for trying to do something similar - with best intentions at heart - I wouldn't recommend it
You are correct. However all the big sites do it, hell even google do it (I'm in the uk, if I goto www.google.com it redirects to google.co.uk) And if you look at the script IF it's a bot it doesn't do anything....
That assumes that the robots will always identify themselves - they don't! (exactly for that reason )
Not personally... But my site's banned and I'm pretty sure that's why. I think it's why the "cloakers" use IP based content delivery scripts though... Because the user agent is so easy to fake/change.
hostip.info seems to have a pretty bad geotargeting system, everytime I visit it I am somewhere else according to it!
Country it's perfect, IMO. City it is not, and never will be. Read the site...They rely on user input...
yes, I did, it uses many of the same methods I have tried. And even country it is much less accurate then it should be, it does not use the full ripe splits for example if you read the code they used to start the db.