|
|
|
| Title : |
Function that does language negotiation based on the Accept-Language header, a cookie or host name |
| Categories : |
HTTP, PHP, Cookies |
 Stig Bakken |
| Date : |
Jan 17th 1999 |
| Grade : |
3 of 5 (graded 5 times) |
| Viewed : |
6173 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Stig Bakken |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?php
/*
* $Id: language.phl,v 1.3 1998/08/03 13:21:45 ssb Exp $
*/
$supported_languages = array(
"no" => 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;
}
?> |
|
| A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | The following snippet gives complete info about all submitted
HTTP_POST_VARS and HTTP_GET_VARS Categories : Variables, HTTP, PHP | | | Smart Counter - This little script is a plain and simple hit counter that uses cookies to determine whether or not the visitor has already been counted. Categories : Cookies, HTML and PHP, PHP | | | This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change Categories : PHP, Arrays, Cookies, MySQL, Databases | | | Simple Password example Categories : PHP, Authentication, Security, HTTP | | | Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database. Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication | | | header -- Send a raw HTTP header Categories : PHP, PHP Functions, HTTP | | | cookie Categories : Cookies, PHP | | | PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | Authentication script to authenticate users in Active Directory through LDAP. Categories : LDAP, Authentication, Cookies, PHP | | | Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP Categories : PHP, HTTP, Regexps | | | Example voting script. Lets people enter suggestions and vote for existing ones. Categories : MySQL, PHP, Cookies, Complete Programs, Databases | | | Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals. Categories : PHP, Filesystem, Cache, Sockets, HTTP | | | A function to check if a URL exists Categories : PHP, CURL, HTTP | |
|
|
|