PHP code example of tnapf / mysqlsessions

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

    

tnapf / mysqlsessions example snippets


use Tnapf\Pdo\Driver;
use Tnapf\MysqlSessions\Controller;

$driver = Driver::createMySqlDriver("root", "password", "database")->connect();

/** @var PDO $driver */
$driver = $driver->driver;

$sessions = new Controller($driver);

$session = $session->create(); // you can supply a timestamp in seconds for when the cookie should expire; default is 7 days

header($session->setCookieHeader()); // sends a set-cookie header with the session id

$session->var = "foo";

// or

$session->set("var", "foo");

unset($session->var);

// or

$session->unset("var");

$sessions->delete($session);

// or

$sessions->delete($session->id);