The following files exists in this folder. Click to view.
m03u02.php61 lines UTF-8 Unix (LF) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
<?php
session_start();
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
}
if(isset($_POST['username'])) {
$_SESSION['username'] = $_POST['username'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/milligram@1.4.1/dist/milligram.min.css">
<style>
input[type="text"] {
max-width: 400px;
}
.button {
font-size: 1.2rem;
padding: 0 15px;
}
</style>
</head>
<body>
<div class="container">
<h2>m03u02</h2>
<form action="" method="post">
<p>
<label for="username">Ange ett namn</label>
<input id="username" name="username" type="text">
</p>
<button type="submit" class="button">Lagra</button>
</form>
<a href="?" class="button">Ladda om sida utan GET-anrop</a> <br>
<a href="?logout=1" class="button">Döda sessionen</a> <br>
<p>
Angivet namn:
<?php
if (isset($_SESSION['username'])) {
echo $_SESSION['username'];
} else {
echo "<p>Inget sparat namn hittat</p>";
}
?>
</p>
</div>
</body>
</html>