PHP code example of ghalambaz / remember-me

1. Go to this page and download the library: Download ghalambaz/remember-me 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/ */

    

ghalambaz / remember-me example snippets


//initialize Properties Object
$properties = new \RememberMe\Properties();
$properties->setDb("user","password","db_name","host"); //your database access info
$properties->setTableUsers("tbl_acl_users"); // table name that you already save your users data
$properties->setColUsername("username"); // column that save username,email or any id of your users in tbl_users

session_set_save_handler(new \RememberMe\RememberMeSessionHandler($properties));
session_start(); //starting session - check for duplication!
$_SESSION['active'] = time();

//strucure of persist function
function persist(\RememberMe\Properties $properties,$username)
{
    //after checking that 
    session_regenerate_id(true);
    $_SESSION[$properties->getSessUname()] = $username;
    $_SESSION[$properties->getSessAuth()] = true;
    // persisting login
    $r = new \RememberMe\RememberMe($properties);
    $r->start();
}

‍‍‍‍//example of check that is user is logged in or not (need to login again)
function is_loggedin($properties)
{
    if (isset($_SESSION[$properties->getSessAuth()]) || isset($_SESSION[$properties->getSessPersist()])) {
        return true;
    } else {
        $autologin = new \RememberMe\RememberMe($properties);
        $autologin->login();
        if (!isset($_SESSION[$properties->getSessPersist()]))
            return false;
        else
            return true;
    }
}

‍//example of logout function structure 
function logout($properties)
{
    $autologin = new \RememberMe\RememberMe($properties);
    $autologin->logout(true);
}

$days = 365;
$properties->setLifetimeDays($days);