keep user logged in

+1 david kevork · August 27, 2014
hi guys i have been making login but i dont know how to store sessions and keep the user logged in 

Post a Reply

Replies

Oldest  Newest  Rating
+1 Franz Schmidt · August 27, 2014
Could you please post your code what you have tried allready.
+3 JOhaL jaTT · August 27, 2014
see this mate 
$_SESSION['userid'] = $db_id;
$_SESSION['username'] = $db_username;
$_SESSION['password'] = $db_pass_str;
setcookie("id", $db_id, strtotime( '+30 days' ), "/", "", "", TRUE);
setcookie("user", $db_username, strtotime( '+30 days' ), "/", "", "", TRUE);
    setcookie("pass", $db_pass_str, strtotime( '+30 days' ), "/", "", "", TRUE); 
+1 Ibrahim Tuzlak · September 1, 2014
I'll try to explain briefly.
The example will be: If user is logged, echo "Logged", otherwise, echo "Not logged"
I'll consider you have the auth system already set
<?php
session_start()

// $validated = bool, depending on if user has authed successfully

if(isset($validated) && $validated==true) {
$_SESSION['logged']="true";
}
else {
$_SESSION['logged']="false";
}





// Now, let's use the session (you may use this on any other page since the session has been set)


// Also, don't forget the session_start() at the very beginning of your PHP code


if(isset($_SESSION['logged']) && $_SESSION['logged']="true" {
echo "Logged";
}
else {
echo "Not logged";
}

?>


I just wrote down the code, didn't test it. I hope there is no any silly syntax errors :D
  • 1

PHP

107,219 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators