Session Class
This is a Session class for you guessed it, managing sessions. Back in the day, when
there weren't many open source frameworks on the market, developers had to code things
from scratch to achieve certain functionality. This class's inception, is the from one of
those instances. With this class you can easily time-out your authenticated users after
a specified interval., (*1)
### Setup
Add a composer.json
file to your project:, (*2)
{
"require": {
"rcastera/session": "v1.0.0"
}
}
Then provided you have composer installed, you can run the following command:, (*3)
$ composer.phar install
That will fetch the library and its dependencies inside your vendor folder. Then you can add the following to your
.php files in order to use the library (if you don't already have one)., (*4)
require 'vendor/autoload.php';
Then you need to use
the relevant class, and instantiate the class. For example:, (*5)
### Getting Started
require 'vendor/autoload.php';
use rcastera\Browser\Session\Session;
$session = new Session();
### Examples
Logging in. (login.php)
1,
'username' => $_POST['username']
);
$session->register(120); // Register for 2 hours.
$session->set('current_user', $user);
header('location: index.php');
exit;
} else {
$errors[] = 'Invalid login.';
}
}
?>
// Your form here.
Secure area once authenticated. (index.php/controller/whatever)
isRegistered()) {
// Check to see if the session has expired.
// If it has, end the session and redirect to login.
if ($session->isExpired()) {
$session->end();
header('location: login.php');
exit;
} else {
// Keep renewing the session as long as they keep taking action.
$session->renew();
}
} else {
header('location: login.php');
exit;
}
?>
Logging out. (logout.php)
end();
header('location: login.php');
exit;
?>
### Contributing
- Fork it.
- Create a branch (
git checkout -b my_branch
)
- Commit your changes (
git commit -am "Added something"
)
- Push to the branch (
git push origin my_branch
)
- Create an Issue with a link to your branch
- Enjoy a refreshing Coke and wait