View sourcecode

The following files exists in this folder. Click to view.

m03u02.php

61 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?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>