set a variable php from another webpage

This can be useful to build a multilingual website. The code is very simple. Suppose to have a variable lang of the body of you pages. Something like this:

<body lang="<?php if(empty($lang)) {echo "it";} else {echo"$lang";} ?>">
 

And suppose that you want set the lang (language) of the target page from a link in a starting page.

You can use a code like the following

In the starting (aaa.1.php):

<p><a href="aaa.2.php?setlang=en">eng</a><br /><a href="aaa.2.php?setlang=it">ita</a><br /><a href="aaa.2.php?setlang=es">esp</a></p>

In the target page (aaa.2.php):

<?php
$lang = $_GET['setlang'];
?>
<html>
 <body lang="<?php if(empty($lang)) {echo "it";} else {echo"$lang";} ?>">
<p>your content here</p>

Lascia un commento

Il tuo indirizzo email non sarĂ  pubblicato. I campi obbligatori sono contrassegnati *