<form action='valider.php' method = 'post'>
Entrez votre pseudo : <input type='text' name='pseudo'/>
<input type = 'submit' value = 'Ouvrez une session!' />
</form>
<?php
echo "<p>Ouverture de session!</p>";
$_SESSION['pseudo'] = $_POST['pseudo'];
$pseudo = $_POST['pseudo'];
echo "<p>Bonjour, $pseudo </p>";
echo "<a href='index2.php'>Retour à l'index</a>";
?>
<?php
if (!isset($_SESSION['pseudo'])){
echo <<< FIN
<form action='valider.php' method = 'post'>
Entrez votre pseudo : <input type='text' name='pseudo'/>
<input type = 'submit' value = 'Ouvrez une session!' />
</form>
FIN;
}
else {
$pseudo = $_SESSION['pseudo'];
echo "<p>Toujours avec vous, $pseudo!</p>";
echo "<p>Destruction de la session!</p>";
session_destroy();
}
?>
index.php
<body>
<center><h1>Bienvenue sur mon site</h1></center>
<p>Entrez vos identifiants:</p>
<form action='validation.php' method = 'post'>
<table>
<tr>
<td>
<strong>login:</strong>
</td>
<td>
<input type ='text' name='login'/>
</td>
</tr>
<tr>
<td>
<strong>mot de passe:</strong>
</td>
<td>
<input type ='password' name='pass'/>
</td>
</tr>
</table>
<input type = 'submit' value='continuer'/>
</form>
<form action='inscription.php' method = 'post'>
<input type = 'hidden' name = 'inscription' value = '1'/>
<input type = 'submit' value = 'inscription'/>
</form>
</body>
validation.php
<?php
if (!empty($_POST['login']) && !empty($_POST['pass'])){
$db = new SQLite3('base_inscrits.db') or die ("Erreur : impossible de se connecter à la base");
$login = $_POST['login'];
$pass = $_POST['pass'];
//echo "login : ".$login."<br/>";
//echo "pwd : ".$pass."<br/>";
$reponse = $db->query("SELECT * from Utilisateur where login = '$login'") or die ("Erreur dans la requête!");
$tuple = $reponse->fetchArray();
//echo "reponse : <br/>";
//echo $ligne;
if ($tuple['pass'] == $pass) {
echo "<p>Connexion réussie!</p>";
$_SESSION['login'] = $login;
} else {
echo "<p>mot de passe invalide!</p>";
session_destroy();
}
} else {
echo "<p>informations incomplètes!</p>";
session_destroy();
}
?>
inscription.php
<body>
<center><h1>Nouvelle inscription</h1></center>
<p>Entrez vos identifiants:</p>
<form action='valider_inscription.php' method = 'post'>
<table>
<tr>
<td>
<strong>Votre nom:</strong>
</td>
<td>
<input type ='text' name='nom'>
</td>
</tr>
<tr>
<td>
<strong>Votre prenom:</strong>
</td>
<td>
<input type ='text' name='prenom'>
</td>
</tr>
<tr>
<td>
<strong>votre e-mail:</strong>
</td>
<td>
<input type ='text' name='adresse'>
</td>
</tr>
<tr>
<td>
<strong>choisissez votre login:</strong>
</td>
<td>
<input type ='text' name='login'>
</td>
</tr>
<tr>
<td>
<strong>choisissez votre mot de passe:</strong>
</td>
<td>
<input type ='password' name='pass'>
</td>
</tr>
</table>
<input type = 'hidden' name = 'valider_inscription' value='1'>
<input type = 'submit' value='continuer'>
</form>
</body>
valider_inscription.php
<?php
$db = new SQLite3('base_inscrits.db') or die ("Erreur : impossible de se connecter à la base");
$login = $_POST['login'];
$pass = $_POST['pass'];
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$adresse = $_POST['adresse'];
//echo $login."<br/>";
//echo $nom."<br/>";
//echo $prenom."<br/>";
$db->exec("insert into Utilisateur values ('$login', '$pass', '$nom', '$prenom', '$adresse')") or die ("<p> <a href='index.php'>Continuer</a> </p>");
$_SESSION['login'] = $login;
echo <<< FIN
Inscription réussie!
<FORM action='salut.php' method = 'post'>
<INPUT type='submit' value='Accéder au site'/>
</FORM>
FIN;
?>
salut.php
<h1>
Salut la Terre!
</h1>
<a href ='logout.php'>Déconnexion</a>
</body>
logout.php
<?php
session_destroy() or die ("deconnexion impossible!");
header('location:index.php');
?>