How to save CakePHP session in Database ?
To store session in Database, you need to create a table in DB so that you can store the session in it.
Follow below steps.
1. Create a table in DB
CREATE TABLE IF NOT EXISTS `users` (
`id` VARCHAR(255) NOT NULL , // id column store the session id,
`data` TEXT NULL ,
`expires` INT UNSIGNED NULL ,
PRIMARY KEY (`id`) )
2. Go to the app/Config/core.php and search the following code.
Configure::write('Session', array(
'defaults' => 'php'
));
Replace above code to following code so that our application can store the session in database.
Configure::write('Session', array(
'defaults' => 'database',
'handler' => array(
'model' => 'User'
)
));
3. Now create a file user.php in model folder and write following code.
class User extends AppModel
{
public function beforeSave($options = array()){}
}
0 Comment(s)