-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogout.php
37 lines (32 loc) · 976 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
33
34
35
36
37
<?php
session_start();
$DB_DSN = 'localhost';
$DB_USER = 'root';
$DB_PASSWORD = '';
$DB_NAME = 'matcha2';
//connect to the newly created database
try {
$conn = new PDO("mysql:host=$DB_DSN;dbname=$DB_NAME", $DB_USER, $DB_PASSWORD);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$online = 0;
try{
$sql = $conn->prepare("UPDATE users SET onlineStatus=:onlineStatus, lastLogin=:lastLogin WHERE id=:userid");
$sql->bindParam(':onlineStatus', $online);
$sql->bindParam(':lastLogin', date("Y/m/d"));
$sql->bindParam(':userid', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
// var_dump($_SESSION);
session_destroy();
// var_dump($_SESSION);
header("Location:index.php");
?>