Code cleanup and some fixes
This commit is contained in:
@ -4,6 +4,18 @@ require_once("_db.php"); //("api/_db.php");
|
||||
|
||||
|
||||
|
||||
// End currently active session
|
||||
function EndSession () {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
if (isset($_COOKIE["PHPSESSID"])) {
|
||||
unset($_COOKIE["PHPSESSID"]);
|
||||
setcookie("PHPSESSID", "", time() - 3600, "/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//session_start();
|
||||
// This ^ should be placed at login stage
|
||||
|
||||
@ -15,23 +27,14 @@ if (isset($_SESSION["userid"])) {
|
||||
$s->bind_param("s", $_SESSION["userid"]);
|
||||
$s->execute();
|
||||
if (!(bool)$s->get_result()->fetch_assoc()) { // If not, then destroy session
|
||||
session_unset();
|
||||
session_destroy();
|
||||
EndSession();
|
||||
echo "user id does not exist";
|
||||
die("user id used in session does not exist");
|
||||
}
|
||||
$LOGGED_IN = true;
|
||||
} else {
|
||||
// ATTENTION: idk will this work, but this can be theoretically unsafe or cause fault
|
||||
|
||||
if (session_status()) {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
if (isset($_COOKIE["PHPSESSID"])) {
|
||||
unset($_COOKIE["PHPSESSID"]);
|
||||
setcookie("PHPSESSID", "", time() - 3600, "/");
|
||||
EndSession();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user