PHP code example of webiik / login

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

    

webiik / login example snippets


$login = new \Webiik\Login\Login($token, $cookie, $session);

// Log-in the user with id 1
$login->login(1);

// Check if the user is logged in 
if ($login->isLogged()) {
    echo 'The user id ' . $login->getUserId() . ' is logged.';
} else {
    echo 'The user is not logged.';
}

// Log the user out
$login->logout();

setSessionKey(string $sessionKey): void

$login->setSessionName('logged');

setNamespace(string $name): void

$login->setNamespace('en');

login($uid, bool $permanent = false): void

// Log in the user with id 1
$login->login(1);

// Permanently log in the user with id 1
$login->login(1, true);

setPermanentCookieName(string $name): void

$login->setPermanentCookieName('PC');

setPermanentLoginStorage(callable $factory, int $days = 30): void

$login->setPermanentLoginStorage(function () {
    $fs = new \Webiik\Login\Storage\FileStorage();
    $fs->setPath(__DIR__ . '/tmp/permanent');
    return $fs;
});

isLogged(): bool

if ($login->isLogged()) {
    echo 'The user id ' . $login->getUserId() . ' is logged.';
} else {
    echo 'The user is not logged.';
}

logout(): void

$login->logout();

setAutoLogoutTime(int $sec): void

// Set the automatic logout after 5 minutes of inactivity between two requests
$login->setAutoLogoutTime(5 * 60);

updateAutoLogoutTs(): void

// Never call this before isLogged, it would lead 
// to the situation, that the user was never logged out
$login->updateAutoLogoutTs();

getLogoutReason(): void

if ($login->getLogoutReason() == $login::MANUAL) {
    // manual logout
} elseif ($login->getLogoutReason() == $login::AUTO) {
    // auto logout due inactivity
}