Visa Källkod

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

NamnTypStorlek
admin.phpPHP Fil612 B
check_login.phpPHP Fil1.1 KB
index.phpPHP Fil1.7 KB
login.phpPHP Fil2 KB
logout.phpPHP Fil710 B

check_login.php

33 lines ISO-8859-1 BOM Unix (LF) - Type: PHP Fil
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
<?php

session_start
(); // Startar sessionen
// Om inte inloggad, men "rememberme"cookie finns, logga in automatiskt
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
    if (isset(
$_COOKIE['rememberme'])) {
        
$_SESSION['loggedin'] = true// Sätt att användaren är inloggad
        
$_SESSION['username'] = $_COOKIE['rememberme']; // Hämtar användarnamn från cookie
        // Sätt rollen Admin, annars user
        
$_SESSION['role'] = ($_COOKIE['rememberme'] === 'Admin') ? 'admin' 'user';
    } else {
        
header("Location: index.php?noaccess=1"); // Skickar till startsidan om inte inloggad
        
exit;
    }
}

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Check login</title>
    <link rel="stylesheet" href="style.css">
    <link rel="icon" href="../../m02/Favicon-a.jpg" type="image/x-icon">
</head>
<body>

</body>
</html>