PHP code example of initphp / redis-session-handler

1. Go to this page and download the library: Download initphp/redis-session-handler 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/ */

    

initphp / redis-session-handler example snippets


> $redis = new \InitPHP\Redis\Redis([
>     'host' => '127.0.0.1',
>     'port' => 6379,
> ]);
>
> $handler = new \InitPHP\RedisSessionHandler\Handler($redis);
> session_set_save_handler($handler, true);
> session_start();
> 

> use InitPHP\Sessions\Session;
> use InitPHP\Sessions\Adapters\RedisAdapter;
>
> $adapter = new RedisAdapter([
>     'host'     => '127.0.0.1',
>     'port'     => 6379,
>     'database' => 0,
>     'ttl'      => 86400,
>     'prefix'   => 'sess_',
> ]);
>
> Session::createImmutable($adapter)->start();
> 


$redis = new \InitPHP\Redis\Redis([
    'host'          => '127.0.0.1',
    'password'      => null,
    'port'          => 6379,
    'timeout'       => 0,
    'database'      => 0,
]);

$sessionHandler = new InitPHP\RedisSessionHandler\Handler($redis);
session_set_save_handler($sessionHandler, true);
session_start();

// You can use the $_SESSION global.