Forum Moderators: mack

Message Too Old, No Replies

Redirect Users based on IP address

redirecting users

         

canadian 3dartist

4:23 pm on Jul 26, 2002 (gmt 0)

10+ Year Member



I've see this post in here before, but they are ancient posts. I was hopping a newer post with newer members would help me with my question.

Redirect based on Country?

I basically have 2 sites. A .ca and a .com Site.

The .ca is canadian content, and the .com is american content.

I need users to be redirected based on IP. If they are US clients, I want them to get the .com site.

Canadian users get the .ca site.

I need this more than any other web tip in here...
PLEASE PLEASE HELP me....

Anyone who can refer me to where I can make this possible.

3D

mavherick

4:42 pm on Jul 26, 2002 (gmt 0)

10+ Year Member



Those are probably the threads you looked at but I'll mention them anyway for others to look at:

IP's from all over the world [webmasterworld.com]
Need some help with IP/country identification [webmasterworld.com]
language based redirection [webmasterworld.com]

So simply put, there's no easy solution to this kind of problem. Some talked about users using proxies that could cause problems. One of the most accurate way seems to use DNS and resloving the host name of the visitor IP.

Hopefully somebody else will be more helpful.

mavherick

canadian 3dartist

3:20 pm on Jul 29, 2002 (gmt 0)

10+ Year Member



Thanx for the links. O.k know that I have users attention, instead of the IP thing I have another solution that people say works pretty good...

I want my site to act like Google

I have a pretty big server, and I get 500 gigs og transfer a month.

So I'mnot worried to much about any problems it may cause....

So like google were it redirects you based on the language. I'm pretty sure they use cookies right? I'd love to get some help on how they do there's weres the best place to find those answers.

:)

Rumbas

3:31 pm on Jul 29, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Welcome canadian_3dartist :)

What about just having a US and Canadian flag on all your pages. This way the Canadians would probably go to the right section of your site and vice versa with the Americans?

Would save you a lot of troubles with people being redirected to the wrong pages just because of their IP.
I'm not sure how it is in Canada, but in Germany fx., users visting through AOL.de are indentified as being from the US.

JamesR

7:58 pm on Jul 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cloaking is one solution for what you are trying to do but it may be complex.

canadian 3dartist

4:15 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



Alright people, I've got a few ways I think to do it. I have the sites, just need the darn code. Its exactly what google.com is doing. Please, anyone know how they do it?

Help :)

JamesR

4:25 pm on Aug 19, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As far as I know, Google uses cloaking technology to achieve that affect.

For more on cloaking see:

Cloaking knowledge base [webmasterworld.com]

Getting the user's country from the IP address [webmasterworld.com]

Language based redirection [webmasterworld.com]

rewboss

7:18 pm on Aug 19, 2002 (gmt 0)

10+ Year Member



I hate the way Google redirects me without asking.

I'm in Germany, but I'm not German. I speak fluent German, but the directory is organized differently (e.g., on Google Deutschland, "Internet" is given its own category, while on Google.com it's subsumed under "Computers").

At home, the relevant cookies allow me to go to the English site when I go to www.google.com and to the German site when I go to www.google.de -- but when I'm working away from home I always end up at Google Deutschland.

Grr..r...r...

saurabh

9:53 pm on Aug 20, 2002 (gmt 0)

10+ Year Member



canadian 3dartist: You may want to check these out:-

Net World Map [networldmap.com]
Geophrase [geobutton.com]

I find them to be highly accurate.

c3oc3o

2:08 pm on Aug 21, 2002 (gmt 0)

10+ Year Member



"So like google were it redirects you based on the language"
In PHP that would be:
if (stristr($HTTP_ACCEPT_LANGUAGE, 'de')) {
Header('Location:germanpage.html');
} elseif (stristr($HTTP_ACCEPT_LANGUAGE, 'fr')) {
Header('Location:frenchpage.html');
}
and so on (some language codes are listed in the post about that topic which was linked in one of the previous messages of this thread, you can also send me a private message for one).

As mentioned in all the linked posts, finding out the country is very difficult - it's not like each country has it's own IP address ranges (the most you can tell from the IP is whether it's administered by the American, European or Asian agency).
You can look the country up in whois queries and filter the country of the organization that owns that IP out of the result, but that would slow your site down, I believe. At least European RIPE also offers their entire whois-database for download if you ask for it, but that's a several-hundred-MB textfile if it's decompressed, because there are so many organizations and companies owning IPs or IP ranges (and the data probably changes all the time!).
Then there's the problem of people using proxy servers, international ISPs etc.

You can get the host name (PHP: $hostname = gethostbyaddr($ip); ), from which you can extract the domain, but there are many ISPs outside the USA using .net, .com and others that don't reflect the actual country.

HTH

tgotchi

12:50 am on Oct 15, 2002 (gmt 0)

10+ Year Member



I found this example with ASP & PHP source code to lookup country by IP address. You might want to try it.

Download it from:
http*//www.location.com.my

[edited by: engine at 10:02 am (utc) on Oct. 15, 2002]
[edit reason] No url drops, please [/edit]

dingman

5:17 pm on Oct 15, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Eep! c30c30, don't do that to me!

Your code will send me to the German version of the site even though I speak better French and my language preferences say so. 'de' *is* in my accept-language request header, but it is the one with the lowest priority. specifically, my header is 'en, fr;q=0.66, de;q=0.33'. That translates roughly as "My native language is English. If you don't have an English version, try French - I'm near-fluent. Failing that, well, I don't see an option for Creole, so I guess you can try German." My German sucks, it's just better than my Spanish or my Russian(to pick two languages I don't speak at all), and I only ever want to see a page in German if you don't have an English or French version.

Just finding the language code in the Accept-Language header isn't enough. You need to find the language code I have the highest preference for that you also support.