Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage
Php > Cookies sample source codes
Function that does language negotiation based on the Accept-Language
Function that does language negotiation based on the Accept-Language header, a cookie or host name 1, /* Norwegian */ "en" => 1 /* English */ ); $default_language = "en"; /* Try to figure out which language to use. */ function negotiate_language($lang) { global $supported_languages, $HTTP_ACCEPT_LANGUAGE; if (isset($supported_languages[$lang])) { return $lang; } /* If the client has sent an Accept-Language: header, * see if it is for a language we support. */ if ($HTTP_ACCEPT_LANGUAGE) { $accepted = explode( ",", $HTTP_ACCEPT_LANGUAGE); for ($i = 0; $i < count($accepted); $i++) { if ($supported_languages[$accepted[$i]]) { return $accepted[$i]; } } } /* One last desperate try: check for a valid language code in the * top-level domain of the client's source address. */ if (eregi( "\\.[^\\.]+$"", $REMOTE_HOST, &$arr)) { $lang = strtolower($arr[1]); if ($supported_languages[$lang]) { return $lang; } } global $default_language; return $default_language; } ?>
Privacy Policy
|
Link to Us
|
Links