Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Save CakePHP session in Database ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 142
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: