-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.php
More file actions
49 lines (40 loc) · 1.11 KB
/
header.php
File metadata and controls
49 lines (40 loc) · 1.11 KB
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
<?php
session_write_close();
session_start();
$user = (isset($_SESSION['current_user'])) ? $_SESSION['current_user'] : null;
$user = (object) $user;
if (isset($_GET['action']) && $_GET['action'] == "logout")
logout();
function logout()
{
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), "", time() - 3600, "/");
}
$_SESSION = [];
session_destroy();
header("location: login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Authetication</title>
</head>
<body>
<header>
<nav>
<ul>
<?php
if (!isset($_SESSION['current_user'])) { ?>
<li><a href="login.php">Login</a></li>
<li><a href="register.php">Register</a></li>
<?php
} else { ?>
<li><a href="?action=logout">Logout</a></li>
<?php } ?>
</ul>
</nav>
</header>