Browse Source

force logout user when login from is rendered

Andrew Dolgov 11 months ago
parent
commit
dcffa74b03
3 changed files with 13 additions and 7 deletions
  1. 2 0
      login.php
  2. 1 7
      logout.php
  3. 10 0
      sessions.php

+ 2 - 0
login.php

@@ -35,6 +35,8 @@
 		} else {
 			$login_notice = "Incorrect username or password";
 		}
+	} else {
+		logout_user();
 	}
 
 ?>

+ 1 - 7
logout.php

@@ -2,13 +2,7 @@
 	require_once "config.php";
 	require_once "sessions.php";
 
-	session_destroy();
-
-	if (isset($_COOKIE[session_name()])) {
-	   setcookie(session_name(), '', time()-42000, '/');
-	}
-
-	session_commit();
+	logout_user();
 
 	header("Location: login.php");
 

+ 10 - 0
sessions.php

@@ -9,6 +9,16 @@
 	ini_set("session.gc_maxlifetime", SESSION_LIFETIME);
 	ini_set("session.cookie_lifetime", SESSION_LIFETIME);
 
+	function logout_user() {
+		session_destroy();
+
+		if (isset($_COOKIE[session_name()])) {
+		   setcookie(session_name(), '', time()-42000, '/');
+		}
+
+		session_commit();
+	}
+
 	if (@$_SERVER['HTTPS'] == "on") {
 		ini_set("session.cookie_secure", true);
 	}