1<?php
2if(isset($_GET['logout'])) {
3 session_destroy();
4 unset($_SESSION['uname']);
5 header('location:login.php');
6}
7?>
1if(isset($_GET['logout'])) {
2 session_destroy();
3 unset($_SESSION['username']);
4 header('location:login.php');
5}
1<?php
2
3ob_start();
4if (!isset($_SESSION))
5 session_start();
6unset($_SESSION['user_id']);
7session_destroy();
8header("location:index.php");
9
1<?php
2 // If the user is logged in, delete the session vars to log them out
3 session_start();
4 if (isset($_SESSION['user_id'])) {
5 // Delete the session vars by clearing the $_SESSION array
6 $_SESSION = array();
7
8 // Delete the session cookie by setting its expiration to an hour ago (3600)
9 if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time() - 3600); }
10
11 // Destroy the session
12 session_destroy();
13 }
14
15 // Delete the user ID and username cookies by setting their expirations to an hour ago (3600)
16 setcookie('user_id', '', time() - 3600);
17 setcookie('username', '', time() - 3600);
18
19 // Redirect to the home page
20 $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
21 header('Location: ' . $home_url);
22?>