PHPackages                             crazy-max/cws-session - 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. crazy-max/cws-session

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

crazy-max/cws-session
=====================

PHP class to manipulate sessions. Data are securely encrypted and sessions are stored in database.

1.10.2(6y ago)4462MITPHPPHP &gt;=5.3.0

Since Aug 22Pushed 6y ago1 watchersCompare

[ Source](https://github.com/crazy-max/CwsSession)[ Packagist](https://packagist.org/packages/crazy-max/cws-session)[ Docs](https://github.com/crazy-max/CwsSession)[ RSS](/packages/crazy-max-cws-session/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (2)Versions (7)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/3a1a4839bec14529b3ffd9625a60fccd1e27ea3d9c8d3a6f8822d487b95e1fc3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372617a792d6d61782f6377732d73657373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crazy-max/cws-session)[![Minimum PHP Version](https://camo.githubusercontent.com/55453b8aba1f0d2c449c2dfa58e6debd503f9d637d2e474960cea8c266371e2f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e332e302d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Build Status](https://camo.githubusercontent.com/288b7b74938f45f48cf7ad1b91dbc7b32a8897be43f76857cf1965b9a36c69a5/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6372617a792d6d61782f43777353657373696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/crazy-max/CwsSession)[![Code Quality](https://camo.githubusercontent.com/0004c9372bd494789b7bb41bef212097cb4da3ca22c701bc55acff7991550023/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f31393061373834363536626234626437626263363034326362393933633839302e7376673f7374796c653d666c61742d737175617265)](https://www.codacy.com/app/crazy-max/CwsSession)[![Become a sponsor](https://camo.githubusercontent.com/2b64183536d3742cfdfdbe2a16c7a26ae05e6a3db44e513ff73defdeed344cc1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f722d6372617a792d2d6d61782d3138313731372e7376673f6c6f676f3d676974687562267374796c653d666c61742d737175617265)](https://github.com/sponsors/crazy-max)[![Donate Paypal](https://camo.githubusercontent.com/86518966c73798ed1c862566d92cd4cdd48152e30ab7f42fb7d5138138231d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f6e6174652d70617970616c2d3030343537632e7376673f6c6f676f3d70617970616c267374796c653d666c61742d737175617265)](https://www.paypal.me/crazyws)

⚠️ Abandoned project
--------------------

[](#warning-abandoned-project)

This project is not maintained anymore and is abandoned. Feel free to fork and make your own changes if needed.

Thanks to everyone for their valuable feedback and contributions.

CwsSession
==========

[](#cwssession)

PHP class to manipulate sessions. Data are securely encrypted and sessions are stored in database.

Installation
------------

[](#installation)

```
composer require crazy-max/cws-session
```

And download the code:

```
composer install # or update
```

Getting started
---------------

[](#getting-started)

Add a new table in your database with the following structure.
You can change the name of the table (sessions) but not the columns.

```
CREATE TABLE IF NOT EXISTS `sessions` (
  `id` varchar(128) NOT NULL,
  `id_user` int(10) unsigned NOT NULL DEFAULT '0',
  `expire` int(10) unsigned NOT NULL DEFAULT '0',
  `data` text NOT NULL,
  `skey` varchar(128) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

**id** - the session id.
**id\_user** - the user id from your application. If you want to use it, use getParamUserId/setParamUserId methods.
**expire** - the session cache expire.
**data** - the session data.
**skey** - unique key for data encryption.

See `tests/test.php` file sample to help you.

### Disconnect all users

[](#disconnect-all-users)

If you want to disconnect all the users from your PHP application, execute this query :

```
TRUNCATE TABLE `sessions`;
```

### Count visitors and users connected

[](#count-visitors-and-users-connected)

If you want to count visitors and users connected on your PHP application, execute this query :

```
SELECT (SELECT COUNT(*) FROM `sessions` WHERE `id_user` > 0 LIMIT 1) AS nb_connected,
(SELECT COUNT(*) FROM `sessions` WHERE `id_user` = 0 LIMIT 1) AS nb_visitors;
```

You have to use the `setParamUserId` method when the user is logged in.

Example
-------

[](#example)

[![](.res/example.png)](.res/example.png)

Methods
-------

[](#methods)

**process** - Start the process.
**start** - To call everytime you want to start a new session instead of session\_start().
**regenerate** - Regenerates the session and delete the old one. It also generates a new encryption key in the database. To use each time a user connects to your application successfully.
**update** - Update specific session vars (user agent, IP address, fingerprint).
**isActive** - Check if the session is active or not.

**getLifetime** - The session life time.
**setLifetime** - Set the session life time (in seconds).
**getCookieDomain** - The domain of the session cookie.
**setCookieDomain** - Set the domain of the session cookie (eg: .foo.com).
**getSessionName** - The session name.
**setSessionName** - Set the session name. (default PHPSESSID).
**isFpEnable** - The fingerprint enable status.
**setFpEnable** - Enable/disable fingerprint.
**getFpMode** - The fingerprint mode.
**setFpModeBasic** - Set the fingerprint mode basic. (default)
**setFpModeShield** - Set the fingerprint mode shield.
**getDbExt** - The database PHP extension used to store sessions.
**setDbExtMysql** - Set the database PHP extension used to store sessions to mysql.
**setDbExtMysqli** - Set the database PHP extension used to store sessions to mysqli.
**setDbExtPdo** - Set the database PHP extension used to store sessions to pdo. (default)
**getDbPdoDriver** - The PDO driver to use. (if db extension is Pdo)
**setDbPdoDriverFirebird** - Set the PDO driver to firebird.
**setDbPdoDriverMysql** - Set the PDO driver to mysql. (default)
**setDbPdoDriverOci** - Set the PDO driver to oci.
**setDbPdoDriverPgsql** - Set the PDO driver to pgsql.
**setDbPdoDriverSqlite** - Set the PDO driver to sqlite.
**setDbPdoDriverSqlite2** - Set the PDO driver to sqlite2.
**setDbPdoDriverSqlsrv** - Set the PDO driver to sqlsrv.
**getDbHost** - The database host name or IP address.
**setDbHost** - Set the database host name or IP address.
**getDbPort** - The database port.
**setDbPort** - Set the database port. Leave empty if your are not sure.
**setDbUsername** - Set the database username.
**setDbPassword** - Set the database password.
**getDbName** - The database name.
**setDbName** - Set the database name.
**getDbCharset** - The database charset.
**setDbCharset** - Set the database charset. Leave empty if your are not sure.
**getDbTableName** - The database table name to store sessions.
**setDbTableName** - Set the database table name to store sessions (default 'sessions').
**getParamFp** - The fingerprint SESSION value.
**getParamUserId** - The user id SESSION value.
**getParamUa** - The user agent SESSION value.
**getParamIp** - The ip address SESSION value.
**getParam** - A SESSION value by key. Use this method instead $\_SESSION var.
**setParamUserId** - Set id\_user SESSION value. A user id from your application.
**setParam** - Set a SESSION key/value. Use this method instead $\_SESSION var.
**getError** - The last error.

How can I help ?
----------------

[](#how-can-i-help-)

All kinds of contributions are welcome 🙌! The most basic way to show your support is to star 🌟 the project, or to raise issues 💬 You can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) 👏 or by making a [Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely! 🚀

Thanks again for your support, it is much appreciated! 🙏

License
-------

[](#license)

MIT. See `LICENSE` for more details.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~231 days

Recently: every ~288 days

Total

6

Last Release

2441d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a2ac50dd173150fc9339728d7b2b1c872b6853111b20e4569844e215f644f632?d=identicon)[crazy-max](/maintainers/crazy-max)

---

Top Contributors

[![crazy-max](https://avatars.githubusercontent.com/u/1951866?v=4)](https://github.com/crazy-max "crazy-max (19 commits)")

---

Tags

databasefingerprintmanipulate-sessionspdophpdatabaseencryptsession

### Embed Badge

![Health badge](/badges/crazy-max-cws-session/health.svg)

```
[![Health](https://phpackages.com/badges/crazy-max-cws-session/health.svg)](https://phpackages.com/packages/crazy-max-cws-session)
```

###  Alternatives

[betterapp/laravel-db-encrypter

Provides database model attribute encryption/decryption

364638.9k8](/packages/betterapp-laravel-db-encrypter)[aplus/session

Aplus Framework Session Library

2211.6M3](/packages/aplus-session)[stefangabos/zebra_session

A drop-in replacement for PHP's default session handler which stores session data in a MySQL database, providing better performance, better security and protection against session fixation and session hijacking

174116.9k2](/packages/stefangabos-zebra-session)[ytake/laravel-couchbase

Couchbase providers for Laravel

3052.1k](/packages/ytake-laravel-couchbase)[gregoryduckworth/encryptable

A simple trait to make attributes encrypted in the database

1953.2k1](/packages/gregoryduckworth-encryptable)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2919.9k](/packages/voku-session2db)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
