Last active
August 29, 2015 14:04
-
-
Save juniorb2ss/a3db0d9b0fab03406a89 to your computer and use it in GitHub Desktop.
StackOverflow [ http://pt.stackoverflow.com/questions/26954/mudar-idioma-do-site ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arrayIdiomas = array('portugues' => 'idioma.portugues.php', 'english' => 'idioma.ingles.php', 'espanol' => 'idioma.espanhol.php', 'alemao' => 'idioma.alemao.php'); // definindo todos os idiomas disponiveis | |
// Definindo o idioma padrão | |
if(!isset($_SESSION['idIdioma'])){ | |
$_SESSION['idIdioma'] = 'portugues'; | |
} | |
if(isset($_REQUEST['idioma'])){ | |
// o idioma seleciona existe? | |
if(array_key_exists($_REQUEST['idioma'], $arrayIdiomas)){ | |
$_SESSION['idIdioma'] = $_REQUEST['idioma']; // seta o idioma selecionado | |
echo "<script>document.location=$_SERVER['HTTP_REFERER']</script>"; // refresh na página | |
exit(); // finaliza o escopo do código | |
} | |
} | |
else{ | |
// idioma definido na sessão é valido? | |
if(array_key_exists($_SESSION['idIdioma'], $arrayIdiomas)){ | |
include $arrayIdiomas[$_SESSION['idIdioma']]; // inclue o arquivo. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment