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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 376
    Comment on it

    In CakePHP you can store the Sessions in the database , So lets try to implement this :

    Because you are storing the session in databse so first you need to create a table in DB so that you can store the session

    CREATE TABLE IF NOT EXISTS `cake_sessions` (
    `id` VARCHAR(255) NOT NULL ,
    `data` TEXT NULL ,
    `expires` INT UNSIGNED NULL ,
    PRIMARY KEY (`id`) )
    
    

    In id column we will store the session id,

    Now we need to configure the CakePHP file so that our application can store the session in DB

    go to the app/Config/core.php and find the following code :

     Configure::write('Session', array(
        'defaults' => 'php'
    )); 
    
    

    here you define the how you will store the session , because we are going to store the session in DB so we will change this code to following code:

     Configure::write('Session', array(
        'defaults' => 'database',
        'handler' => array(
            'model' => 'cake_sessions'
        )
    ));
    
    

    now create a file name cake_sessions.php and write following code there

    class cake_sessions extends AppModel{
           public function beforeSave($options = array()){
           // Useful in cases where you would want to store extra data - like an IP-address - in your session handler
        }
    }
    
    

    and save this file in modles folder.

    So using this you can save the session in DB .

 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: