The following files exists in this folder. Click to view.
m03u2.php51 lines UTF-8 Unix (LF)
<?php
require_once "functions.php";
// Hantera session
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'create_session':
if (isset($_POST['username'])) {
$_SESSION['name'] = sanitize($_POST['username']);
}
break;
case 'kill_session':
session_unset();
session_destroy();
break;
}
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<title>m03u2</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<h1>Lösningsförslag m03u2</h1>
<h2>Sessionstatus</h2>
<?php if (isset($_SESSION['name'])): ?>
<p>Sessionen innehåller: <strong><?= $_SESSION['name'] ?></strong></p>
<?php else: ?>
<p>Sessionen är tom – ingen användare är inloggad.</p>
<?php endif; ?>
<form action="?action=create_session" method="POST">
<label for="username">Ange namn:</label>
<input type="text" name="username" id="username" required>
<input type="submit" value="Lagra användarnamn">
</form>
<p><a href="?action=kill_session">Döda sessionen</a></p>
<p><a href="?">Ladda om sidan</a></p>
</main>
</body>
</html>