J'aimerais votre avis sur les aspects "sécurité" de ma façon de faire pour le changement de langue
Voici le fichier pour lequel j'ai des doutes:
CODE
<?php // Changementlangue.php
echo '<form method="post" action="'.$nom_fichier.'-en.php">';
echo '<input type="image" src="english.gif" alt="" />';
echo '<input type="hidden" name="lang" value="en" />';
echo '</form>';
echo '<form method="post" action="'.$nom_fichier.'.php">';
echo'<input type="image" src="francais.gif" alt="" />';
echo'<input type="hidden" name="lang" value="fr" />';
echo '</form>';
?>
echo '<form method="post" action="'.$nom_fichier.'-en.php">';
echo '<input type="image" src="english.gif" alt="" />';
echo '<input type="hidden" name="lang" value="en" />';
echo '</form>';
echo '<form method="post" action="'.$nom_fichier.'.php">';
echo'<input type="image" src="francais.gif" alt="" />';
echo'<input type="hidden" name="lang" value="fr" />';
echo '</form>';
?>
Le traitement se fait ici:
CODE
<?php //lect_cookie.inc.php
$langue_cookie = $_COOKIE["monsite_lang"]; // Lecture du cookie
if (isset ($langue_cookie)) { if ($langue_cookie=='en') $langue='en'; }
else $langue='fr';
if (isset ($_POST['lang'])) // si on vient de cliquer sur changement langue, on adapte le cookie et on change la valeur $langue
{ if ($_POST['lang']=="en") {
setCookie("monsite_lang", "en", (time() + (60*60*24*180))); // c'est l'anglais, on crée le cookie pour 6 mois
$langue='en'; }
if ($_POST['lang']=="fr") {
setCookie("monsite_lang", "fr", (time() - 10)); // c'est le français, on efface le cookie
$langue='fr'; }
}
?>
$langue_cookie = $_COOKIE["monsite_lang"]; // Lecture du cookie
if (isset ($langue_cookie)) { if ($langue_cookie=='en') $langue='en'; }
else $langue='fr';
if (isset ($_POST['lang'])) // si on vient de cliquer sur changement langue, on adapte le cookie et on change la valeur $langue
{ if ($_POST['lang']=="en") {
setCookie("monsite_lang", "en", (time() + (60*60*24*180))); // c'est l'anglais, on crée le cookie pour 6 mois
$langue='en'; }
if ($_POST['lang']=="fr") {
setCookie("monsite_lang", "fr", (time() - 10)); // c'est le français, on efface le cookie
$langue='fr'; }
}
?>
Ici, le fichier index:
CODE
<?php //index.php
include("lect_cookie.inc.php");
if (!isset ($langue)) { $langue="fr";}
$nom_fichier="index"; // permet de renseigner drapeau.inc.php
if ($langue=="fr") $extension="";
else $extension="-en";
$fr_title="Titre en français";
$en_title="English title";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<?php
if($langue == 'fr') echo "<title>".$fr_title."</title>\n";
else echo "<title>".$en_title."</title>\n";
?>
</head>
<body>
<?php
if ($langue == 'fr' ) require_once 'fr_textes_index.php'; // chargement du fichier dans la bonne langue
else require_once 'en_textes_index.php';
include ("changementlangue.php");
// Ma page 1
echo '<h1>'.$titre.'</h1> ';
echo "$texte1 <br />";
echo '<a href="introduction'.$extension.'.php" >'.$lien1.'</a><br />';
?>
</body>
</html>
include("lect_cookie.inc.php");
if (!isset ($langue)) { $langue="fr";}
$nom_fichier="index"; // permet de renseigner drapeau.inc.php
if ($langue=="fr") $extension="";
else $extension="-en";
$fr_title="Titre en français";
$en_title="English title";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<?php
if($langue == 'fr') echo "<title>".$fr_title."</title>\n";
else echo "<title>".$en_title."</title>\n";
?>
</head>
<body>
<?php
if ($langue == 'fr' ) require_once 'fr_textes_index.php'; // chargement du fichier dans la bonne langue
else require_once 'en_textes_index.php';
include ("changementlangue.php");
// Ma page 1
echo '<h1>'.$titre.'</h1> ';
echo "$texte1 <br />";
echo '<a href="introduction'.$extension.'.php" >'.$lien1.'</a><br />';
?>
</body>
</html>
et le fichier qui sera appelé en anglais:
CODE
<?php // index-en.php
$langue="en";
include("index.php");
?>
$langue="en";
include("index.php");
?>
Les textes en français:
CODE
<?php // fr_textes_index.php
$titre="Mon site en français";
$texte1="Première page";
$lien1="Vers ma seconde page";
?>
$titre="Mon site en français";
$texte1="Première page";
$lien1="Vers ma seconde page";
?>
et en anglais:
CODE
<?php // en_textes_index.php
$titre="My english site";
$texte1="first page";
$lien1="To my second page";
?>
$titre="My english site";
$texte1="first page";
$lien1="To my second page";
?>
La page 2
CODE
<?php // introduction.php
include("lect_cookie.inc.php");
if (!isset ($langue)) { $langue="fr";}
$nom_fichier="introduction"; // permet de renseigner la routine changementlangue
if ($langue=="fr") $extension="";
else $extension="-en";
$fr_title="Titre page 2 en français";
$en_title="English title page 2";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<?php
if($langue == 'fr') echo "<title>".$fr_title."</title>\n";
else echo "<title>".$en_title."</title>\n";
?>
</head>
<body>
<?php
if ($langue == 'fr' ) require_once 'fr_textes_introduction.php'; // chargement du fichier dans la bonne langue
else require_once 'en_textes_introduction.php';
// Ma page 2
echo '<h1>'.$titre.'</h1> ';
echo "$texte1 <br />";
echo '<a href="index'.$extension.'.php" >'.$lien1.'</a><br />';
?>
</body>
</html>
include("lect_cookie.inc.php");
if (!isset ($langue)) { $langue="fr";}
$nom_fichier="introduction"; // permet de renseigner la routine changementlangue
if ($langue=="fr") $extension="";
else $extension="-en";
$fr_title="Titre page 2 en français";
$en_title="English title page 2";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<?php
if($langue == 'fr') echo "<title>".$fr_title."</title>\n";
else echo "<title>".$en_title."</title>\n";
?>
</head>
<body>
<?php
if ($langue == 'fr' ) require_once 'fr_textes_introduction.php'; // chargement du fichier dans la bonne langue
else require_once 'en_textes_introduction.php';
// Ma page 2
echo '<h1>'.$titre.'</h1> ';
echo "$texte1 <br />";
echo '<a href="index'.$extension.'.php" >'.$lien1.'</a><br />';
?>
</body>
</html>
Son appelant en anglais:
CODE
<?php // introduction_en.php
$langue="en";
include("introduction.php");
?>
$langue="en";
include("introduction.php");
?>
Textes correspondant en français:
CODE
<?php // fr_textes_introduction.php
$titre="Mon site en français, page 2";
$texte1="Deuxiemme page";
$lien1="Retour première page";
?>
$titre="Mon site en français, page 2";
$texte1="Deuxiemme page";
$lien1="Retour première page";
?>
... et en anglais:
CODE
<?php // en_textes_introduction.php
$titre="My english site, page 2";
$texte1="Second page";
$lien1="Turn back to first page";
?>
$titre="My english site, page 2";
$texte1="Second page";
$lien1="Turn back to first page";
?>
En plus, il y a les 2 images en .gif qui affichent "Français" ou "English"
J'aurais bien mis le tout dans un fichier zip pour que ce soit facile à charger, mais je ne trouve pas la commande.
C'est un peu compliqué, mais ça permettrait de séparer les textes du code des pages, d'autoriser le référencement, et de faciliter la navigation grâce aux cookies.
Voila, je préfère poser la question avant de mettre en ligne, si quelqu'un pouvais me dire si ça tient la route au point de vue sécurité, ça serait bien!
Merci d'avance.