1. Go to this page and download the library: Download tomkirsch/psession library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomkirsch / psession example snippets
class MyPage extends Controller{
function index(){
$session = service('session'); // attempts to read session from cookie, falling back on persistent cookies...
if(empty($_SESSION['user_id'])){
return $this->response->redirect('auth/login');
}
// user is logged in...
}
}
class Auth extends Controller{
protected function doLogin(string $email, string $password, bool $rememberMe){
$session = service('session');
// ber me' cookie
if($rememberMe){
$this->response->setCookie([
'name'=>'user_email',
'value'=>$user->user_email,
'expire'=> config('app')->persistentSessionExpiry,
'secure' => TRUE,
'httponly'=>TRUE,
'samesite'=>'Lax',
]);
}else{
$this->response->deleteCookie('user_email');
}
}
}
protected function doLogout(){
$session = service('session');
$session->destroy();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.