From fd034ca5fa5ff55f2e5941a5f1535543e05a9726 Mon Sep 17 00:00:00 2001 From: nolanwhy Date: Sun, 12 Feb 2023 11:21:19 +0100 Subject: [PATCH] g --- core/classes/user.php | 19 ++++++++++++++++--- index.php | 9 ++++++--- login.php | 8 ++++---- register.php | 8 ++++---- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/core/classes/user.php b/core/classes/user.php index ac84c81..c981dd9 100644 --- a/core/classes/user.php +++ b/core/classes/user.php @@ -7,12 +7,25 @@ class User { public function __construct($con, $id) { $query = $con->prepare('SELECT * FROM users WHERE id=:id'); $query->bindParam(':id', $id); - $query->execute(); + $query->execute(); + $this->con = $con; $this->sqlData = $query->fetch(PDO::FETCH_ASSOC); } - public static function isLoggedIn() { - return isset($_SESSION["user"]); + public function isLoggedIn() { + if(isset($_SESSION["user"])) { + $q = $this->con->prepare("SELECT * FROM users WHERE id = :id"); + $q->bindParam(':id',$this->sqlData["id"],PDO::PARAM_INT); + $q->execute(); + $usr = $q->fetch(); + if($usr) { + return true; + } else { + return false; + } + } else { + return false; + } } public function getMoney($short) { diff --git a/index.php b/index.php index c0e5a9b..273efef 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,13 @@ isLoggedIn()) { + header('location: /home'); + exit; +} + $getitstarted = new PartyStarter; $getitstarted->bootstrap(); $countofarray = rand(0, count($arraybackground)-1); diff --git a/login.php b/login.php index 80b983a..6716414 100644 --- a/login.php +++ b/login.php @@ -1,9 +1,5 @@ header(); $passwordiswrong = false; $userdontexist = false; $user = new User($con, 0); +if($user->isLoggedIn()) { + header('location: /home'); + exit; +} if(isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['pass']; diff --git a/register.php b/register.php index cdda51c..2dab707 100644 --- a/register.php +++ b/register.php @@ -1,9 +1,5 @@ isLoggedIn()) { + header('location: /home'); + exit; +} $userexists = false; if(isset($_POST['submit'])) { $username = $_POST['username'];