View Single Post
Old 11-22-2001, 09:12 PM  
Carpenter
Registered User
 
Join Date: Nov 2001
Location: LA, CA
Posts: 19
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?)

*/

Carpenter is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote