View sourcecode

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

m03u02.php

66 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
62
63
64
65
66
<?php 
session_start
();    //Startar sessionen

if (isset($_POST['username'])){
    
$_SESSION['username']= $_POST['username'];
    
setcookie("username",$_POST['username'], time()+20);
}

if (isset(
$_GET['destroy_session'])) {    //Om man tryckt på destroy så kommer allt att tömmas. 
    
session_unset();
    
session_destroy();
    
header("Location: ?");
    exit;


}
if (isset(
$_GET['destroy_cookie'])) {    
    
setcookie("username",$_POST['username'], time() - 3600);
    
header("Location: ?");
    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>
</head>
<body>
<?php 



if(isset($_SESSION['username'])){
    echo 
'Session inehåller:'.$_SESSION['username'];
}else{
    echo 
'Det finns ingen användare';
}
echo 
"<br>"; 

if (isset(
$_COOKIE['username'])){
    echo 
"Ditt namn är:".$_COOKIE["username"];
}else {
   echo 
"Du har inte någon cookie";
}
?>

<form method="post">
    <label for="username">Användarnamn:</label>
    <input type="text" id="username" name="username"><br>

    <button type="submit" value="skicka" name="skicka">Lagra användarnamn</button><br>

    <a href="?destroy_session=true">Döda sessionen</a><br>
    <a href="?destroy_cookie=true">Döda cokkien</a><br>
    <a href="?">Ladda om sidan</a>
</form>


</body>
</html>