View sourcecode

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

m03u3.php

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

    if(isset(
$_GET['action'])){
        switch(
$_GET['action']){

            case 
'create_session':
                
$_SESSION['namn'] = $_POST['Namn'];
                
setcookie('namn'$_POST['Namn']);
                break;

            case 
'kill_session':
                
session_unset();
                
session_destroy();
                break;

            case 
'remove_cookie':
                
setcookie('namn'''time() - 3600);
                
header('location: m03u3.php?');
        }
    }
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>m03u3</title>
    <link rel="stylesheet" href="bulma.css">
</head>
<body class="m-5">
    
    <form action="?action=create_session" method="post">
        <p><label for="Namn">Namn</label>
        <input class="mb-3" type="text" name="Namn" id="Namn" required placeholder="Ange ditt namn"></p>
        <button class="button" type="submit" name="submit" value="send">Skicka</button>
    </form>


    <?php
        
if(isset($_SESSION['namn'])){
            echo 
"<p>Sessionen innehåller namnet: " $_SESSION['namn'] . "</p>";
        } else if(isset(
$_COOKIE['namn'])){
            echo 
"<p>En cookie med namnet " $_COOKIE['namn'] . " finns</p>";
        } else{
            echo 
"<p>Ingen namn är aktivt eller lagrat </p>";
        }
    
?>
    <br>

    <a class = "button" href="?action=kill_session">Döda sessionen</a>
    <a class = "button" href="?">Ladda om sida utan GET-anrop</a>
    <a class = "button" href="?action=remove_cookie">Ta bort cookie</a>

</body>
</html>