Skip to content
Snippets Groups Projects
Commit 931c4786 authored by Raghav's avatar Raghav
Browse files

Login test implemented using session

parent 177ec227
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,8 @@ include_once '_includes/Database.class.php'; ...@@ -6,6 +6,8 @@ include_once '_includes/Database.class.php';
include_once '_includes/User.class.php'; include_once '_includes/User.class.php';
include_once '_includes/Session.class.php'; include_once '_includes/Session.class.php';
Session::start();
function load_template($name) function load_template($name)
{ {
......
...@@ -4,10 +4,31 @@ include 'libs/load.php'; ...@@ -4,10 +4,31 @@ include 'libs/load.php';
$user = "devyani "; $user = "devyani ";
$pass = "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) { if ($result) {
echo "Login success" . "\n". "password = $result[password]"; Session::set('is_loggedin', true);
Session::set('session_user', $result);
} else { } else {
echo "Login failed"; echo "login failed";
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment