Reputation: 335
Or in PHP in general. I need to check if a user is logged in when accessing a certain page. Tutorials recommend using sessions e.g
$sessionData = array('username'=>$username, 'status'=>1);
$this->session->set_userdata($sessionData);
And for better security they recommend using a db table.
What if I just store username and status in a database and then change status to 0 when people log out?
Whenever they need access to a certain page I just check if the status 1.
Upvotes: 0
Views: 62
Reputation: 32232
session_start()
PHP sets a cookie in the user's browser with a randomly-generated ID.$_SESSION
will [by default] be stored in a file in session.save_path
at the end of the script. This file is identified by the session ID.session_start()
in your script PHP can go and retrieve that session file and restore the contents to $_SESSION
.Literally anything you will write will simply be re-implementing this already-written behaviour, but without the added layers of security contributed over the years to the PHP project.
Upvotes: 1