Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How would you create Sessions in Cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.55k
    Comment on it

    Hello readers , this is a small blog on session in cakephp.

    Sessions are the most useful and important function of PHP. I think Sessions are used in every website. Sessions can be used in  e-commerce website, job portals, payroll systems , healthcare systems and many more.

    Sessions are already built in cakephp. Cakephp Session component provides way to use client data between different pages in your application. The Session component is used to interact session information between different pages.

    You can configure your session by using the line of code
    Configure::write('', 'php'); in app/config/core.php.


    Sessions can be set by using write() function

    $this->Session->write('name', 'peehu');

    this will set the session variable name to peehu equivalent to $_SESSION[‘name’] = ‘peehu’;


    We can create array structures in the Session by using dot notation. So

    $this->Session->write('User.username', '');  would similar to:

    array('User' =>     array('username' => ''));


    You can get the value of session variable by using read() function

    $name = $this->Session->read('name');

    Returns the value of name in the Session. If name is null the entire session will be returned.


    Some  Important Functions :

    1. $this->Session->consume(‘<session variable name>’); is used to read and delete a value from the Session. This is useful when we want to combine reading and deleting values in one operation.

    2. $this->Session->check(‘<session variable name>’); is used to check whether session is set or not.

    3. $this->Session->delete('<session variable name>'); is used to delete a particular session variable

    4. $this->Session->destroy(); The destroy method will delete the session and all session data stored in the temporary file system. It will then destroy the PHP session and then create a fresh session.

 0 Comment(s)

Sign In

Sign up using

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: