View sourcecode

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

m03u02.php

57 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
<?php
session_start
();

if(isset(
$_POST["name"])) {
    
$_SESSION["name"] = $_POST["name"];
}
if(isset(
$_GET["logout"])) {
    
session_destroy();
    
header("Location: m03u02.php");
    exit;
}
?>

<!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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">

<?php
if(isset($_SESSION["name"])) {
    echo 
"<h2 class='text-center mt-4'>Hej "  .$_SESSION["name"]."</h2>";
    echo 
"<br>";
} else {
    echo 
"<h2 class='text-center mt-4'>Det finns ingen användare</h2>";
    echo 
"<br>";
}
?>
<div class="d-flex justify-content-center mt-5">
    <div class="card p-4 shadow" style="width: 400px;">
        <?php
        
echo "
                <form method='POST'>
                    <input type='text' name='name' required placeholder='Skriv ditt namn' class='form-control mb-3'>
                    <div class='d-flex gap-2'>
                        <input type='submit' value='Skicka' class='btn btn-primary w-100'>

                        <a href='m03u02.php' class='btn btn-success w-50'>
                            Ladda om
                        </a>
                    </div>
                </form>
            "
;
        if(isset(
$_SESSION["name"])) {
            echo 
"<br>";
            echo 
'<a href="m03u02.php?logout=1" class="btn btn-danger w-100">Logga ut</a>';
        }
        
?>
    </div>
</div>
    
</body>
</html>