PHP Classes

PHP MySQLi Session Handler: Store sessions in a database using MySQLi

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 682 All time: 4,766 This week: 80Up
Version License PHP version Categories
dbsh 1.0.0BSD License5PHP 5, Databases, User Management
Description 

Author

This class is a session handler that store sessions in a database using the MySQLi.

It can register as a session handler with functions to open, close, read, write, destroy and garbage collect sessions.

The main class uses another class that stores and retrieves session records from a given MySQL database table using the MySQLi extension.

Picture of Mohammad Mostafa Shahreki
Name: Mohammad Mostafa ... <contact>
Classes: 6 packages by
Country: Iran Iran
Age: 41
All time rank: 8998 in Iran Iran
Week rank: 163 Up2 in Iran Iran Up

Recommendations

Assign and lookup sessions
Sessions class or equivalent

Example

<?php
function AutoLoad($class) {
    require_once
'class.' . $class . '.php';
}
spl_autoload_register('AutoLoad');
$dbsh = new DBSessionHandler();
?>
<!doctype html>
<html>
<head>
<title>Database Session Handler</title>
<meta charset="utf-8" />
</head>
<body>
<?php
echo '<p>There are ' . $dbsh->onlineCount() . ' user(s) online.</p>' . PHP_EOL;
echo
'Online users: <br />' . PHP_EOL;
foreach(
$dbsh->onlineUsers() as $user) {
    echo
$user . '<br />' . PHP_EOL;
}
?>
</body>
</html>


  Files folder image Files (3)  
File Role Description
Plain text file class.DB.php Class Database Wrapper Class
Plain text file class.DBSessionHandler.php Class Database Session Handler Class
Accessible without login Plain text file index.php Example Example Script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:682
This week:0
All time:4,766
This week:80Up
User Comments (1)
Excellent, the most necessary!
7 years ago (Sergey)
70%StarStarStarStar