View Full Version : redirect people based on where they live...
queerfm
11-20-2006, 05:52 PM
Hi i was wondering i have a site that i want to make so when someone goes to my website the index page redirects them to there own countrys url. Like
http://www.YOURWEBSITE.com/Index.html
then if in the UK it goes to
http://www.YOURWEBSITE.com/UK/index.html
or if in Australia it goes to
http://www.YOURWEBSITE.com/AUSTRALIA/index.html
Also i would like it to remember where the person cames from
If there was a URL code that would help me with this that would be great.
Thanks
mwinter
11-20-2006, 06:30 PM
Hi i was wondering i have a site that i want to make so when someone goes to my website the index page redirects them to there own countrys url.
Then place clearly labelled links somewhere on your site. Either launch straight into the site with some sensible default, or display the links upfront.
Mike
djr33
11-21-2006, 02:28 AM
Just use cookies to store their location.
tech_support
11-21-2006, 06:32 AM
Or you can use IP Geographical Location Technology.
djr33
11-21-2006, 06:55 AM
That is very complex, though.
there was a recent thread about it... search for that... might help.
tech_support
11-21-2006, 06:56 AM
Isn't there some sort of PHP code that'll do the trick?
djr33
11-21-2006, 06:57 AM
Not by default.
It's all discussed in the thread.
Options are either incomplete, expensive or complex. Usually a few of those.
tech_support
11-21-2006, 07:45 AM
I found this CSV file of all the locations of the IP addresses.
Can you use this and make it into a PHP script?
Url: http://www.b3ta.cr3ation.co.uk/data/rar/IPLocations.rar
djr33
11-21-2006, 08:52 AM
.rar.... meh.
might work. can't open it to look, though...
queerfm
11-21-2006, 09:27 AM
I don't know how to make scripts... Is there anyone that i could ask to do this, or what would i search for in google.
Thanks
tech_support
11-21-2006, 11:07 PM
Ah, forgot you're on a Mac.
Here's the ZIP file.
http://www.b3ta.cr3ation.co.uk/data/zip/IPLocations.zip
mwinter
11-22-2006, 10:40 PM
Or you can use IP Geographical Location Technology.
Which, at its worst, won't even get the right continent.
At the very least, the user must be given the opportunity to correct any assumptions made at any time.
Mike
djr33
11-23-2006, 01:34 AM
That list is quite interesting.
It wouldn't be too hard, using PHP, to code a redirect based on that.
However, not sure on the validity of the list... it would be a pain if someone got sent to a page with a language they cannot understand.
It's cool, though.
I could try coding it.
I'm away for Thanksgiving... but might get a chance on the trip if things are quiet for a bit.
At the very least, the user must be given the opportunity to correct any assumptions made at any time.
I was thinking about this as well.... good idea.
However, what if the redirect is based on language?
How would you do the link? I suppose that assuming english is probably the best idea, since most web users (though not all) speak it. I wonder if there's a way to graphically represent it.
Ideas?
mwinter
11-23-2006, 02:16 AM
However, what if the redirect is based on language?
I assume that the idea is to provide region-sensitive content, but if it is for language then the country is irrelevant. A French man or woman working in the UK is more likely to want to read something in French than in English. The Accept-Language header should be used as the starting point to negotiate language variants.
How would you do the link?
Well, that depends, really, on various issues. The capabilities of the server are important (and, when it comes to content negotiation, so is the configuration), as are the intentions of the site owner: is there region-specific content, only language, or even both? If the latter, should all content be translated, or does that, too, depend on the country (countries with more than one official language, for example)? That would be an organisational headache, but workable.
I suppose that assuming english is probably the best idea, since most web users (though not all) speak it.
As I wrote above, content negotiation should be the first place to start. That may lead to English for the most part, anyway, but it's a good initial guess. If it's wrong, at least with links to other variants in plain sight, the user won't be that troubled.
I wonder if there's a way to graphically represent it.
No. Languages should be presented as text, stating the name of that language, in that language: English, Deutsch, Svenska, 日本語, etc. Certainly, national flags are not the way to go.
Mike
tomyknoker
11-23-2006, 04:23 AM
Just use cookies to store their location.Hey DJ,
Is there any discussion on how to use cookies for locations?
djr33
11-23-2006, 05:24 AM
There's nothing specific about that.
In the cookie, just store country=US, and that's it.
It just REMEMBERS what their original decision, in the case of manual input (either no IP check or the IP check was wrong and user-corrected).
Mike, I'm not suggesting flags or a graphical way to represent the NAME of a language, but to have on a page, a small logo in the corner that was, for example, a mouth and a globe, implying "click here to change your language," since every language you had available would need to be represented if it was text, so any link to "change language" would be very large, so that everyone could read it. A universal "click here for language options" image would be great. Just thinking about anything that might represent that well.
mwinter
11-23-2006, 10:51 PM
Mike, I'm not suggesting flags or a graphical way to represent the NAME of a language, but to have on a page, a small logo in the corner that was, for example, a mouth and a globe, implying "click here to change your language,"
Oh, sorry. It read to me that you meant to represent each language graphically.
It's possible, I suppose, you'd have to consider that the icon would need global recognition. It's probably easier, and more obvious, to absolutely-position direct language links at the top of the document - the links themselves should occur at the end of the document source.
since every language you had available would need to be represented if it was text, so any link to "change language" would be very large, so that everyone could read it.
I think it would be rare for there to be many languages. Even the UN only maintains a handful of choices.
The list would only be composed of single words, so it's not going to be that long.
Mike
djr33
11-24-2006, 09:53 PM
Still, five language links could take up an annoying amount of space... but... yeah, I see what you mean.
Hmm... here's some fun php code for that list above--
I'd worry about how long it would take... that's a lot of text... 6mb... ew!
<?php
function ip2loc($ip) {
list($ip1,$ip2,$ip3,$ip4) = explode('.',$ip);
$ipn = $ip4+$ip3*1000+$ip2*1000000+$ip1*1000000000;
$list = file('ip.csv');
foreach($list as $line) {
$line = str_replace('"','',$line);
$line = explode(',',$line);
$lineip = $line[0];
list($lineip1,$lineip2,$lineip3,$lineip4) = explode('.',$lineip);
$lineipn = $lineip4+$lineip3*1000+$lineip2*1000000+$lineip1*1000000000;
$lineip2 = $line[1];
list($lineip1,$lineip2,$lineip3,$lineip4) = explode('.',$lineip2);
$lineipn2 = $lineip4+$lineip3*1000+$lineip2*1000000+$lineip1*1000000000;
if ($ipn >= $lineipn && $ipn <= $lineipn2) {
$loc = $line[5];
//or, for the two letter code:
//$loc = $line[4];
break;
}
}
if(empty($loc)) {
$loc = 'default_here';
}
return $loc;
}
?>
Untested, but I think it'll work.
Might take a really long time, though...
Note that this just returns the location as $loc, so you'd do...
$location = ip2loc($ip);
And then do a redirect based on that....
EDIT: Tested!!
It works.
Using this IP:
"62.186.76.0","62.186.76.63","1052396544","1052396607","SE","Sweden"
http://www.ci-pro.com/misc/phptest/loc/?ip=62.186.76.27
Try it using the get variable, ?ip=
Or, if left blank, it'll tell you where YOU are.
Using that, we can test whether it's accurate...
Works for me.... anyone else?
Also, doesn't seem to take all that long. There's certainly a pause... but... 2 sec? Not much more than that.
Might depend on where on the list you check, though.
//tested...
hmm... for the last one on the list, it took about 3 sec. Cool.
tech_support
11-25-2006, 04:58 AM
I swear I saw a red flash when viewing your page.
Nice, but shouldn't it have a link something like "Not your country? Click here" and let them set their own country.
djr33
11-25-2006, 05:47 AM
Yeah... obviously... just outputs the country now.... just set up a basic framework for now.
tech_support
11-25-2006, 05:48 AM
Oh, ok. Nice :D
tomyknoker
11-25-2006, 07:50 AM
That's brilliant! I tried this http://www.ci-pro.com/misc/phptest/loc/?ip=58.106.12.120 and it worked test it out!
tomyknoker
11-25-2006, 07:52 AM
How often do you think the list would need to be updated?
djr33
11-25-2006, 07:30 PM
I think it's pretty cool too, thanks.
Really, though, the issue at this point is the list of IPs.
I don't know if it would ever need to be updated. Not sure if they switch. However, I'd assume that, over years, with new countries forming and such (rare, but it does happen) they would need to add/change some.
So... as often as possible, I assume, but... every month is probably fine.
Though I really don't know.
Maybe they rotate on a more regular basis.
Might even be fine to just do it once a year.
That's the other thing... we don't even know how accurate the list is. Tech, where did you get the list? Is it a reliable site?
Seems to me like it works just fine, but it's hard to know.
And, even if they list did need to be updated regularly, no problem... it's just a file... just replace the old one in the FTP and the php script will use that instead... no issue with changing the php, etc.
tech_support
11-26-2006, 04:24 AM
Tech, where did you get the list? Is it a reliable site?
MaxMind - GeoLite Country
http://www.maxmind.com/app/geoip_country
It's a pretty reliable site, and they say it's approx. 97% accuracy.
djr33
11-26-2006, 08:20 AM
The info there is worth noting, though.
First, it suggests using a database... er... yeah. :p
But... actually, the csv list in itself works alright.
Secondly, their license creates issues... but seems alright. At least it's free.
Considering 97% accuracy, you need, then, to have a "fix it" link for those who aren't rerouted correctly. But that's pretty good. As good as I would've expected, if not better. 99% for the paid version. Meh. Gimics :p
Updates monthly (so that's how much you should update your list), though weekly kinda for the paid thing. That was a bit unclear.
Still.... interesting concept.
EDIT: Hmm...
Under the license agreement, all advertising materials and documentation mentioning features or use of this database must display the following acknowledgment: "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."
Ok, so looks like it is just saying in DOCUMENTATION and advertising materials, not on the site itself... that's a lot nicer. So just if I wrote a manual for my page, I guess. So I could still include it on my page as a feature, as long as I didn't redistribute and call it a feature. Not bad. Quite fair on their part.
tomyknoker
12-15-2006, 03:30 AM
Is it worth paying the $50 and getting the 99% accurate one?
djr33
12-15-2006, 03:35 AM
Do you want 97% or 99%? Is it worth $50 to you?
...
tomyknoker
12-15-2006, 03:38 AM
Do you want 97% or 99%? Is it worth $50 to you?
...Hmmm basically I'm only worried about GST, so that's in Australia... And then the US. Is it fairly simple to set it up? So that if a user from Australia type in www.mydomain.com they go to www.mydomain.com, and vice versa?
djr33
12-15-2006, 06:16 AM
Well, there are seveal options....
1. if australia, redirect to .au (all else to .com)
2. if US, redirect to .com (all else to .au)
3. actually figuring out the "closest" location to each nation in the list, so that, for example, South Africa would go to Australia as it's closer than the US.
I'd suggest 1.
If so, just add this line to the end of the php code I supplied earlier--
1. Include the function from earlier at the top of your script.
Add these lines (after that):
$loc = ip2loc($_SERVER['REMOTE_ADDR']);
if ($loc == 'Australia' || $loc == 'New Zealand' || $loc == 'Indonesia') {
dostuffhere--REDIRECT;
}
I'm assuming that New Zealand, and maybe Indonesia are considered "Australia" more than "US", but feel free to adjust.
tomyknoker
12-17-2006, 02:34 AM
Well, there are seveal options....
1. if australia, redirect to .au (all else to .com)
2. if US, redirect to .com (all else to .au)
3. actually figuring out the "closest" location to each nation in the list, so that, for example, South Africa would go to Australia as it's closer than the US.
I'd suggest 1.
If so, just add this line to the end of the php code I supplied earlier--
1. Include the function from earlier at the top of your script.
Add these lines (after that):
$loc = ip2loc($_SERVER['REMOTE_ADDR']);
if ($loc == 'Australia' || $loc == 'New Zealand' || $loc == 'Indonesia') {
dostuffhere--REDIRECT;
}
I'm assuming that New Zealand, and maybe Indonesia are considered "Australia" more than "US", but feel free to adjust.Thnaks heaps dj I'll give it a try! You're a legend! Hey could I get your opinion on my post http://www.dynamicdrive.com/forums/showthread.php?t=15708 point 2... Just need an expert opinion on which way to go about it! :)
djr33
01-16-2007, 12:43 AM
This is old, but I just realized something fun you could do with the code. Since the list returns AOL users as a specific type, you could just ban everyone who uses AOL from your site :p
benniaustin
01-17-2007, 02:22 AM
We were discussing this at work for one of our larger clients, to redirect them to the store, for whatever country they were in automatically using their ip address. In the end we decided that not only is it difficult to produce, (possible of course, but not worth the hours invested) but also not 100% foolproof.
I don't really know the specifics behind it, I'm no network guy, so I could have completely misunderstood, but something about people accessing the site on a computer at work from large companies, with offices overseas might somehow have an IP that appears to be from the US (or whatever country the servers are in). I dont know these IT guys go way over my head sometimes, I dont pretend to know how computers work, I just work/play on the damn things.
Like I said, I could be completely off... Flame on.
tech_support
01-17-2007, 02:31 AM
Well, you can always have a "Not your country? Click here" link somewhere on the page.
djr33
01-17-2007, 03:42 AM
The system isn't foolproof, but it's implementation is intended to add to the ease of use for your site if there is, indeed, some type of multiple language/country setup. Having the 'not your country' link is crucial, if for nothing else than people who might be traveling at the time.
Rockonmetal
01-25-2007, 06:00 PM
Your Best Guess is to have a prompt Box that says
"What Country are you from"
Then it will take the user to their country's page or what ever.
djr33
01-25-2007, 10:58 PM
No. The best option is setting this up with a backup. The worst it'll do is guess wrong, but it could do the same with English. Just make it clear to check.
One clean option would be to do that but just have it seed the language choice.
"Are you from [Spain]?" Then let them continue or switch the dropdown.
tech_support
09-20-2007, 10:22 AM
This is another random idea.
We could restrict administration access to a specific country like Australia, so it'll err... cut the hackers.
Thoughts?
tomyknoker
09-20-2007, 03:03 PM
You don't like Australians??
lord_havoc
09-20-2007, 03:22 PM
We were discussing this at work for one of our larger clients, to redirect them to the store, for whatever country they were in automatically using their ip address. In the end we decided that not only is it difficult to produce, (possible of course, but not worth the hours invested) but also not 100% foolproof.
I don't really know the specifics behind it, I'm no network guy, so I could have completely misunderstood, but something about people accessing the site on a computer at work from large companies, with offices overseas might somehow have an IP that appears to be from the US (or whatever country the servers are in). I dont know these IT guys go way over my head sometimes, I dont pretend to know how computers work, I just work/play on the damn things.
Like I said, I could be completely off... Flame on.
Yeah, I'm on a computer at school in south-east texas... it said I'm in Sweden. But I would think the auto-redirect with an option to change would be the way to go.
djr33
09-20-2007, 04:17 PM
Restricting based on this method is very flawed because the system isn't perfect. And on top of that, a hacker would be able to find a proxy to get around it anyway, so you'd just be limiting legitimate visitors.
As for it being off, that's true. Having the option is crucial, and you will need to choose:
1. Just choose a country/language, usually that of the webhost/webmaster.
2. Guess as well as you can with the above method.
Then, with either, let the user correct it.
Both methods have advantages and disadvantages, so I'd say just think about what would work best for your visitors.
Would you rather your page guess their country in most cases, or would you rather have it default to English to be sure it didn't guess something unexpected, like Sweden.
tech_support
09-21-2007, 07:28 AM
You don't like Australians??
Nah, I'm saying to only allow the administration part for Australians.
Restricting based on this method is very flawed because the system isn't perfect. And on top of that, a hacker would be able to find a proxy to get around it anyway, so you'd just be limiting legitimate visitors.
Only I will use the admin panel. And besides, it's against the law to run proxies in Australia.
Athos
09-28-2007, 03:09 PM
hey think about this with your 'not your country click here' link, if that just updates the list couldn't someone theoretically add 'yournameland' as a country, over the ip for say Norway:confused:
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.