PDA

View Full Version : How can i redirect users country based??



jobesoft
April 16th, 2001, 14:27
An PHP Script would be nice. But an Perl Script would work fine also.

Thank you for your help.

akersche
April 22nd, 2001, 08:07
hi,
you should have first to ask yourself, how you wanna detect the country or language...

An easy solution would be just to use java, to get the language of the used browser.

Otherwise you can detect the IP of the user and find that way the country... (rather tricky)

Also you can get the domain of the user and set the language for the domain ending (com, net... english; de, at...german)

I would recommend the first solution... But consider that some people use an english browser version, although there are not in an english speaking country (but then they should understand english anyway)

Greetings
Arno

Woofcat
April 22nd, 2001, 11:39
Why Java? You can get the language easily in php/perl...

jobesoft
April 22nd, 2001, 12:28
how can i get the language in php???

!ben
April 22nd, 2001, 17:21
Originally posted by jobesoft
how can i get the language in php???

In PHP:

Try using the $HTTP_ACCEPT_LANGUAGE to get the users language.

And for the country:



<?php
$host = gethostbyaddr($REMOTE_ADDR);
$result = strrchr($host, ".");
echo $host.' is the host address<br>The country is'.$result;
?>


Note: This just returns the extension of the user's host url :). So if the host uses a .com domain it'll return .com - however most non-US hosts use domains of their own country (for example mine returns 'uk').