diff --git a/libs/load.php b/libs/load.php index cc91e437f493e1cf7ebb30cb77c0cb86e6fc1fd8..6136689bb81f818dcfba958733b148f6091d6d28 100644 --- a/libs/load.php +++ b/libs/load.php @@ -6,6 +6,8 @@ include_once '_includes/Database.class.php'; include_once '_includes/User.class.php'; include_once '_includes/Session.class.php'; +Session::start(); + function load_template($name) { diff --git a/logintest.php b/logintest.php index ff89471cae611379a354cd5957071128b76b2a91..cc7380c81f67aab14b901d02909585439a8ccc10 100644 --- a/logintest.php +++ b/logintest.php @@ -4,10 +4,31 @@ include 'libs/load.php'; $user = "devyani "; $pass = "devyani"; -$result = User::login($user, $pass); + +if(isset($_GET['logout'])){ + Session::destroy(); + + die("Successfully Destroyed session..<br><br><a href = logintest.php>Login again</a>"); +} +// Check if the session already exist return this statement +if (Session::get('is_loggedin') == true) { + $userdata = Session::get('session_user'); + print("Welcome back," . $userdata['username']); + + // To logout send "logout" through GET method through link + print("<br><br> <a href = logintest.php?logout>logout</a>"); + $result = $userdata; +} +// else try to login +else { + printf("no session found, trying to login now...."); + $result = User::login($user, $pass); +} + +// check if the user details is present in session and store in session if ($result) { - echo "Login success" . "\n". "password = $result[password]"; + Session::set('is_loggedin', true); + Session::set('session_user', $result); } else { - echo "Login failed"; + echo "login failed"; } -