ExampleΒΆ

In this example the backend is going to be redis , the global reference name will be UID, and the hash algorithim will be sha512.

For example, you can store in the reference UID, the current user id and configure your site to only accept users to loggin once, avoiding with this duplicate entries/access using the same user/password.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

require_once 'dalmp.php';

$cache= new DALMP\Cache\Redis('127.0.0.1', 6379);

$handler = new DALMP\Sessions\Redis($cache, 'UID');

$sessions = new DALMP\Sessions($handler, 'sha512');

/**
 * your login logic goes here, for example suppose a user logins and has user id=37
 * therefore you store the user id on the globals UID.
 */
$GLOBALS['UID'] = 37;

/**
 * To check if there is no current user logged in you could use:
 */
if ($sessions->getSessionRef($GLOBALS['UID'])) {
    // user is online
    exit('user already logged');
} else {
    $sessions->regenerate_id(true);
}

/**
 * You can use $_SESSIONS like always
 */
$_SESSIONS['foo'] = 'bar';

A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.

Donating helps ensure continued support, development and availability.

dalmp


comments powered by Disqus