<?php
session_start();
if(isset($_POST['erase'])){
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
session_start();
}
elseif(isset($_POST['changer'])){
if(!empty($_POST['Name']) && !empty($_POST['Username']) && !empty($_POST['Age']) && !empty($_POST['algo']) ) {
$_SESSION['user']=array();
$_SESSION['user']['name']=$_POST['Name'];
$_SESSION['user']['user_name']=$_POST['Username'];
$_SESSION['user']['age']=$_POST['Age'];
$_SESSION['user']['algo']=$_POST['algo'];
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Changement d'utilisateur</title>
</head>
<body>
<div>
<form action="test.php" method="POST">
<table style="width:50%; border:solid; border-width: 1px;">
<tr>
<th>Name</th>
<th>Username</th>
<th>Age</th>
<th>Type</th>
</tr>
<tr>
<td><input type="text" name="Name" size="39" required value="<?php echo (!empty($_SESSION['user']['name'])?$_SESSION['user']['name']:NULL) ?>" ></td>
<td><input type="text" name="Username" required size="28" value="<?php echo (!empty($_SESSION['user']['user_name'])?$_SESSION['user']['user_name']:NULL) ?>" ></td>
<td><input type="text" name="Age" required size="8" value="<?php echo (!empty($_SESSION['user']['age'])?$_SESSION['user']['age']:NULL) ?>" ></td>
<td>
<select name="algo" required>
<option value="">-- Sélectionner --</option>
<option value="Player" <?php echo (!empty($_SESSION['user']['algo']) && $_SESSION['user']['algo']=="Player"?'selected':NULL) ?> >Player</option>
<option value="Gamer" <?php echo (!empty($_SESSION['user']['algo']) && $_SESSION['user']['algo']=="Gamer"?'selected':NULL) ?> >Gamer</option>
<option value="Admin" <?php echo (!empty($_SESSION['user']['algo']) && $_SESSION['user']['algo']=="Admin"?'selected':NULL) ?>>Admin</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="changer" value="Changer" /></td>
<td colspan="2"><input type="submit" name="erase" value="Tout effacer" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>