Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to save session in Mysql database using CakePhp?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.00k
    Comment on it

    Sometimes the web infrastructure do not share session data with each other. For this reason, sessions may be lost between requests.
    Using MySQL effectively ripps out this problem, as all session data is directed to and from the database server rather than the web server itself.
    Storing sessions in a database also has the effect of added privacy and security, as accessing the database requires authentication.

    For this you have to create a table likewise cake_sessions as an example:

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

    Well the next step you can check in by editing the core.php file in the Config folder so that the database can be used for the cakephp session.

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

    Lastly you can create a file in your model folder associated with your data base i.e cake_session.php

    <?php
    class cake_sessions extends AppModel{
    }
    ?>
    

 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: