browser lang:en
Learn php/walkthrough
One of the common feature of many websites is the "choose language" option, usually indicated with a list of flags.. so, with php is possible to give a professional touch to your web site letting php choosing which is your visitors' language as the choice is based on the default browser language used at that moment.
In this case is useful to create a function to speed up your site building or mantainance, simply calling the function as often as needed. But first of all let's examine wich parameter we have to deal with.
Open up your favourite php editor program and type
echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
echo $result = substr($lang, 0, 2);
// $lang is the variable, 0 is the point where start to count as the beginnig
// and 2 is where to stop trimming the string, so only two letters.
function yourfunctionname($optionalparameter)
// NOT use ; or it won't work to end this line code
{
//your code
}
function comefrom()
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($lang, 0, 2) == 'en')
{
// if the user's browser language is set to english
// do something
} else {
// if the user's browser language is NOT set to english
// do something else
}
}
function comefrom()
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($lang, 0, 2) == 'en')
{
header("Location: english.php");
} else {
header("Location: french.php");
}
}
PHP is one of the most widely used open-source server-side scripting languages that exist today. With over…
in:Scripts and tutorials (0 comments)In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS…
in:Scripts and tutorials (0 comments)Every single day, someone, somewhere is discussing something important to your business; your brand, your executives, your…
in:Scripts and tutorials (0 comments)The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a…
in:Scripts and tutorials (0 comments)Because of the near-spherical shape of the Earth, calculating an accurate distance between two points requires the use…
in:Scripts and tutorials (1 comments)With this script we can limit the download speed // local file that should be send to the client $local_file…
in:Scripts and tutorials (0 comments)Some hosts disabled the ini setting allow_url_fopen. This also means that the ability to easily grab images…
in:Scripts and tutorials (0 comments)The act to verify if a file exists, is one of more important tasks related to files operations,…
in:Scripts and tutorials (0 comments)
