PHPackages                             pitch7900/phpsqlsessionhandler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pitch7900/phpsqlsessionhandler

ActiveLibrary[Database &amp; ORM](/categories/database)

pitch7900/phpsqlsessionhandler
==============================

Sql session handler for Php

0486PHP

Since Aug 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/pitch7900/PhpSqlSessionHandler)[ Packagist](https://packagist.org/packages/pitch7900/phpsqlsessionhandler)[ RSS](/packages/pitch7900-phpsqlsessionhandler/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PhpSqlSessionHandler
====================

[](#phpsqlsessionhandler)

This library will allow to handle PHP session in a databases. This is mainly for authenticated sessions and to maintain sessions between many php servers instances. It also allow to have more than one http request at once after session start.

Prerequisites
-------------

[](#prerequisites)

### Composer requirements

[](#composer-requirements)

```
"php": "^7.3|^7.4|^8",
"illuminate/database": "^6|^7|^8|^9",
"symfony/var-dumper": "^5|^6"
```

### Database

[](#database)

Minimum for getting this code to work is to have a Database with a table named "sessions" declared like follow

```
--
-- Table structure for table `sessions`
--

DROP TABLE IF EXISTS `sessions`;
CREATE TABLE IF NOT EXISTS `sessions` (
  `id` varchar(32) NOT NULL,
  `timestamp` int(10) UNSIGNED DEFAULT NULL,
  `data` mediumtext,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

Database should be declared in your app before loading the session using Illuminate capsule manager

Code declaration in php (sample)
--------------------------------

[](#code-declaration-in-php-sample)

This is the way to call this function

```
use Pitch7900\SessionsHandler\DBSessionsHandler;

session_cache_limiter('public');
ini_set("session.cookie_httponly", 1);
session_name('APPS_SESSID');

//Use a custom SessionHandler Based on database.
$handler = new DBSessionsHandler(3600,'user',$rootPath."/logs/sessions.log",false);
session_set_save_handler($handler, true);
session_start();
```

DBSessionsHadnlder Declaration
------------------------------

[](#dbsessionshadnlder-declaration)

By default a non authenticated session will only last 30 seconds of iddle.

```
Pitch7900\SessionsHandler\DBSessionsHandler::__construct

__construct
