WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Multilingual php webpage
Categories : PHP, Languages, Cookies Click here to Update Your Picture
Kevin Solan
Date : Aug 16th 2008
Grade : 4 of 5 (graded 4 times)
Viewed : 10500
File : 4842.zip
Images : No Images for this code example.
Search : More code by Kevin Solan
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples 
 

Assuming you've got the translation for everything (every phrase/paragraph) you want on your page, a simple, 3-option language check will present your page in your visitor's language.

1.: On 1st visit, the code will check the browser language of the visitor and display your page accordingly.

2.: If the visitor prefers another language, he/she can choose it from a drop-down menu.

3.: Either way, a cookie is set recording the visitor's chosen language so as to display automatically in this language on subsequent visits. This is the first check to be made by the code on any visit.

1.XXXXXX First, you need the language-selection include (langfile.php):

<?php
/*Check_if_user_has_changed_language: */
if(isset($lang)){/*If_so:*/
setcookie("ling",$lang,time()-60*60*24*365,"/",".YourWebSite.com",0);/*Wipe_previous_cookie*/
setcookie("ling",$lang,time()+60*60*24*365,"/",".YourWebSite.com",0);/*Whatever_the_means_lang_has_been_stored,_store_latest_lang_in_new_cookie:*/
//echo "<script language=\"JavaScript\">alert('Selected language=$lang')</script>";/*UnComment_to_check*/
}else{/*If_user_has_NOT_changed_language:*/
if(isset($_COOKIE['ling'])){/*Check_if_user-language_cookie_is_set._If_so:*/
$lang=$_COOKIE['ling'];
setcookie("ling",$lang,time()-60*60*24*365,"/",".YourWebSite.com",0);/*Wipe_previous_cookie*/
setcookie("ling",$lang,time()+60*60*24*365,"/",".YourWebSite.com",0);
//echo "<script language=\"JavaScript\">alert('Cookie language=$lang')</script>";/*UnComment_to_check*/
}else{/*If_user-language_neither_selected_nor_in_cookie,_choose_browser_language:*/
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
setcookie("ling",$lang,time()+60*60*24*365,"/",".YourWebSite.com",0);
//echo "<script language=\"JavaScript\">alert('Your browser language=$lang')</script>";/*UnComment_to_check*/
}
}
?>


2.XXXXXX A simple switch/case function will provide the language content to the server, easiest to keep in its own script (langs.php), example:

<?php

   
switch ($lang){    /*The switch/case function is used to select the $lang language variable that the visitor has selected, or that has been drawn from his cookie or his browser language */

//-------ENGLISH

case 'en':
$Title =     "Multilingual Web pages.";
$Mdesc =     "Languages, Translation, multilingual multimedia";
$Mkw =         "translation, multilingual, audio, video, communication, translate, voiceover";
$intro =     "Offer yourself a multilingual website accessible to the REST of the world too!";
// etc.
   
break;


//-------FRANCAIS

case 'fr':
$Title =     "Pages Web multilingue, rich media, multimedia, etc.";
$Mdesc =     "toutes les langues en une seule page web";
$Mkw =         "langues, traduction, multilingue, communication, traduire";

$intro =     "Offrez-vous un site Web accessible au RESTE du monde aussi !";
//  etc.
   
break;

//-------
}
?>


3.XXXXXX Then, at the top of your target page (index.php), call the language-select include:

include ($path."langfile.php"); ?> <!-- includes cookie -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head id="Head">
    <?php include ($path."langs.php"); ?>
<title><?php echo "$Title" ?></title>
</head>
<body> <!-- text called from "langs.php" variables --> 
<!-- ...etc.etc. -->
</body>



Secure Login
Categories : PHP, MySQL, Cookies, Security
Simple Cookie example
Categories : PHP, Beginner Guides, Cookies
cookie
Categories : Cookies, PHP
Cross Browser Session Starter
Categories : PHP, Sessions, Cookies
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
With this class you can use cookies with chips
Categories : PHP, Cookies
PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL
Function that does language negotiation based on the Accept-Language header, a cookie or host name
Categories : HTTP, PHP, Cookies
Example voting script. Lets people enter suggestions and vote for existing ones.
Categories : MySQL, PHP, Cookies, Complete Programs, Databases
how to check if a string contains a letter from a different language?
Categories : PHP, Regexps, Languages
A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
PHP Cookies - Simple cookie write/read methods that allow basic encryption
Categories : PHP, Cookies, Security, Encryption
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
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Store, retrieve and delete cookies using JavaScript.
Categories : Java Script, Cookies, Beginner Guides, Cookies