PHPBuilder - Language Switch

RSS Twitter

Language Switch

by: D Smith
May 7, 2002

Here is a quick and easy way to provide one to one page correspondece for an english/french, english/spanish, etc
bilingual site. This little code sample is dependent on the directory stucture of the site being all in one
language. All you have to do is create a page called language_switch.php and then in your navigation include
file just link to this page

(e.g. <a href="/includes/language_switch.php).

The scipt on the page language_switch.php will take care of the rest.

Here is the code that will be in the language_switch file


	$completeNewURL = "";
	$referer = "$HTTP_REFERER ";
	$brokenDownReferer = "";
	if (stristr($referer, "/en/")){
		$brokenDownReferer = str_replace("/en/", "/fr/", $referer);
		$brokenDownReferer = str_replace("/fr/", "/en/", $referer);
	//These two lines of code will redirect the user to the corresponding 
	//french/english version of the page they were just on.
	header ("Location: $brokenDownReferer");


Comment and Contribute

Your comment has been submitted and is pending approval.

D Smith



(Maximum characters: 1200). You have characters left.