![]() |
redirecting surfers by country?
Hi,
Can anyone tell me the best way to redirect surfers based on their country? The best way I found so far was a php script that used the language of the browser. Would a perl script or htaccess with a domain look-up create too much overhead? TIA |
here's the script, BTW....
/* LANGUAGE REDIRECTION SCRIPT Copyright http://www.adulttypeins.com/ 2001. This script redirects visitors to different pages based on the default language preference setting in their browser. You will need to use the 2-letter language codes from the ISO 639 standard when naming your files. You can find these ISO 639 codes here:- http://www.unicode.org/unicode/onlinedat/languages.html Disclaimer: this script isn't guaranteed to work as documented, or indeed do anything at all - and it may well blow up in your face. Approach with caution, and carry a big stick! You may use this script on your site or redistribute it free, as long as you leave this header intact, including the copyright and URL. */ // The actual program starts below <? $langtmp = getenv("HTTP_ACCEPT_LANGUAGE"); // Read the browser default language $lang2 = substr($langtmp,0,2); // Throw away the junk filler in the code if(file_exists("$lang2.html")){ // See if a file exists for the language header("Location: http://www.DOMAIN.com/$lang2.html // yes - send them to that page }else{ header("Location: http://www.DOMAIN.com/default.html // no - feed them the default } ?> // The actual program ends above /* INSTRUCTIONS 0. Rename this script to "language.php" (or whatever you like!) 1. Upload the script in TEXT mode into the directory in which you want to run it (your server will need to be set up to use PHP, of course!) 2. Create a "default.html" file which should contain the page that you want visitors to see if you don't have content for their particular language. 3. Create as many "LANGUAGE.html" files as you want to have languages on your site. LANGUAGE should be the 2-letter ISO 639 code for the language, for instance "en" for English or "fr" for French (in this example you would create files called "en.html" and "fr.html" 4. Upload the default.html file and the various language files. 5. Modify the 2 "header" lines to match the full URL of the directory into which you just uploaded the language files. (Don't forget to change DOMAIN into YOUR domain! 6. Test the script. If it works, you should be redirected to the page corresponding to your browser's language (or the default.html page if you didn't create a page for your language). NOTE: You can check that both "paths" through the script work by creating a language file matching your browser setting (the script should send you to the appropriate LANGUAGE.html page) and then deleting that language file ( the script should send you to default.html) ADDITIONAL TIPS A. If you want to feed lost visitors through this script, you can set up a .htaccess file to redirect 404 error codes through the script. Look up "htaccess file" in your favorite search engine for more information. B. Some hosts allow you to create a default page, "index.php", which will be run automatically when people come to your root URL. If you want ALL site traffic to be filtered through this script, try making an index.php file. C. You can send people to any URL on the web via this script - you don't have to limit yourself to sending people to other pages on your own site! So you could, for example, redirect visitors to various affiliate program URLs in different languages. GOOD LUCK AND HAVE FUN WITH THIS! IF YOU FIND A BUG, PLEASE EMAIL typeins AT bigfoot.com (hey, I want to beat the spambots, ok?) */ |
Quote:
Redirection based on language (either using php, java, perl, C, Apache etc) seems the be the best solution at this point. ------------------ Pay-As-You-Go Hosting FREE Trial! Below $.90/GB Dedicated Hosting Limited Time Specials EnergyHosting - Energizing your business |
Thanks RK,
So, I guess a link to a cgi script in perl looking for the HTTP_ACCEPT_LANGUAGE value would be the best way to redirect some foreign traffic to my favorite top site ;-) |
All times are GMT -7. The time now is 11:15 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123