-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
40 lines (36 loc) · 1.07 KB
/
index.php
File metadata and controls
40 lines (36 loc) · 1.07 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
<?php
session_start();
require "backend/db.php";
if (($_SESSION['uId'])==true) {
echo '<script>localStorage.setItem("sessionID", "' . $_SESSION['uId'] . '");</script>';
$text = 'wow! you are login successfully';
} else {
echo '<script>localStorage.removeItem("sessionID");</script>';
header('location:logout.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="assets/img/favicon.png" type="image/x-icon">
<title>main page</title>
</head>
<body>
<h1><?=$text?></h1>
<button type="submit" name="logout" onclick="logout()">Logout</button>
<script>
function logout() {
localStorage.removeItem('sessionID');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'logout.php', true);
xhr.onload = function () {
window.location.href = 'login.html';
};
xhr.send();
}
</script>
</body>
</html>