Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
Working logout script
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyniP committed Sep 21, 2012
1 parent 080863c commit 7b26ba6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
17 changes: 5 additions & 12 deletions admin/logout.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<?php
session_start();

$_SESSION = array();

if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}

session_destroy();
header("Location: login.php", true, 301);


require_once("../includes/config.php");
require_once("../includes/functions.php");
db_connect();
logout();
?>
11 changes: 0 additions & 11 deletions admin/session.php

This file was deleted.

13 changes: 12 additions & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function is_login() {
if (mysql_num_rows($db_result) != 1) {
// User's session has expired.
return false;
session_destroy();
} else {
$db_row = mysql_fetch_assoc($db_result);
$db_result = mysql_query("SELECT * FROM ".DB_PREFIX."users WHERE id='".$db_row['uId']."'");
Expand Down Expand Up @@ -208,5 +209,15 @@ function require_login() {
}
}
function clean_old_sessions() {
$db_results = mysql_query("DELETE FROM ".DB_PREFIX."session WHERE time<='".strtotime("-2 weeks")."'");
mysql_query("DELETE FROM ".DB_PREFIX."session WHERE time<='".strtotime("-2 weeks")."'");
}
function logout() {
if (isset($_SESSION[base64_encode('user')])) {
$session = $_SESSION[base64_encode('user')];
$session = mysql_real_escape_string(trim($session));
mysql_query("DELETE FROM ".DB_PREFIX."session WHERE session='".$session."'");
clean_old_sessions();
session_destroy();
header("Location: ".get_phurl_option('site_url'));
}
}

0 comments on commit 7b26ba6

Please sign in to comment.