-
Notifications
You must be signed in to change notification settings - Fork 0
/
logout.php
32 lines (28 loc) · 912 Bytes
/
logout.php
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
<?php
require_once("functions.php");
require_once("db-const.php");
session_start();
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
// update status to offline
$sql = "SELECT status from users WHERE id={$_SESSION['user_id']}";
$result = $mysqli->query($sql);
$user = $result->fetch_array();
$timestamp = $user['status'] - 300;
$sql = "UPDATE users SET status={$timestamp} WHERE id={$_SESSION['user_id']}";
$result = $mysqli->query($sql);
## finally destroying the session
// unset all session variables
$_SESSION = array();
// destroy the session cookie
if(isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-50000, '/');
}
// destroy the session
session_destroy();
redirect_to("login.php");
?>