par
supercanard » 12 oct. 2007, 11:00
En fait je ne veut pas vérifier que la session est ouverte dès le début.
Je crois que j'ai réussi.
Au tout début sur la page index j'ouvre une session avec rien dedans
session()
Ensuite quand on s'identifie je test si c'est correct, je créé la variable de session et je redirige :
<?php
if (isset($_POST['identifiant'])) {
if (empty($_POST['identifiant']) || empty($_POST['passe'])) {
exit();
}
if ($_POST['identifiant'] != $identifiant) { // SI IDENTIFIANT INCORRECT
echo '<script langage="text/javascript">document.location.href="index.php?page=connexion&alerte='.$mess_identifiant.'"</script>';
exit();
}
if ($_POST['identifiant'] == $identifiant) { // SI IDENTIFIANT OK
if ($_POST['passe'] != $passe) { // Si pass incorrect
echo '<script langage="text/javascript">document.location.href="index.php?page=connexion&alerte='.$mess_motpasse.'"</script>';
exit();
}
if ($_POST['passe'] == $passe) { // Si pass correct
$_SESSION['identifiant']= $identifiant;
echo '<script langage="text/javascript">document.location.href="administration.php"</script>';
}
}
}
?>
Par contre du coup vu que la variable $_SESSION['utilisateur'] n'existe pas avant , dois-je l'initialiser auparavant ? $_SESSION['utilisateur']= ''
Maintenant j'ai un autre problème : Mes variables contenant les message d'erreur (ex : $mess_motpasse) ne s'affiche plus sur la page mais ils apparaissent dans l'url.
Ca aussi il me semble que ça a un rapport avec la config php et les variables globales ? Enfin je crois...
En fait je ne veut pas vérifier que la session est ouverte dès le début.
Je crois que j'ai réussi.
Au tout début sur la page index j'ouvre une session avec rien dedans
[php]session()[/php]
Ensuite quand on s'identifie je test si c'est correct, je créé la variable de session et je redirige :
[php]<?php
if (isset($_POST['identifiant'])) {
if (empty($_POST['identifiant']) || empty($_POST['passe'])) {
exit();
}
if ($_POST['identifiant'] != $identifiant) { // SI IDENTIFIANT INCORRECT
echo '<script langage="text/javascript">document.location.href="index.php?page=connexion&alerte='.$mess_identifiant.'"</script>';
exit();
}
if ($_POST['identifiant'] == $identifiant) { // SI IDENTIFIANT OK
if ($_POST['passe'] != $passe) { // Si pass incorrect
echo '<script langage="text/javascript">document.location.href="index.php?page=connexion&alerte='.$mess_motpasse.'"</script>';
exit();
}
if ($_POST['passe'] == $passe) { // Si pass correct
$_SESSION['identifiant']= $identifiant;
echo '<script langage="text/javascript">document.location.href="administration.php"</script>';
}
}
}
?>[/php]
Par contre du coup vu que la variable $_SESSION['utilisateur'] n'existe pas avant , dois-je l'initialiser auparavant ? $_SESSION['utilisateur']= ''
Maintenant j'ai un autre problème : Mes variables contenant les message d'erreur (ex : $mess_motpasse) ne s'affiche plus sur la page mais ils apparaissent dans l'url.
Ca aussi il me semble que ça a un rapport avec la config php et les variables globales ? Enfin je crois...