Using Sessions
How to use sessions
What is session anyways? According to php.net session is a “way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.” As for me session is like a super global array which can be passed to different pages using the session_start() function. Sessions are very useful especially an on page that requires users to be logged. Because sessions can track weather a user is still logged or not. So let’s get started using sessions in log in cases.
First of all you have to insert the session_start() function at the most top of your coded. So it must be found on line 0 of your codes. For example.
<?php session_start(); ?>
But some servers like mine displays error even if the session_start() is already at the most top of your code so you add this to your code to solve this problem.
<?php
session_cache_limiter(`nocache`);
session_start();
?>
And you need to do a session_start() on every page if you want the user to be logged in order to access the page. So now how do we determine if the session of the user is still active or not? So after you check if the username & password of the user is correct you create a session for the user to know if the user is still active or not. So after checking if the user is valid you do this.
<?php
$_SESSION[`active`] = true;
?>
The word `active` is not constant, you can change it to anything you want. You can even change it to something like $_SESSION[`weeee`] = active; it really doesn’t matter as long as you remember it. So to check if the user is still active, on every page that requires a user to be logged at the most top you do this. Read more »







