简体   繁体   中英

CakePHP: how to register the session?

In PHP5, the code: session_register("");

my code:

function login() {
        // Don't show the error message if no data has been submitted.  
        $this->set('error', false);

        // Production mode. No output. For AJAX
        Configure::write('debug', 0);

        // Does not render the view
        // Others method : $this->render(false, false);
        $this->autoRender = false;

        // The most important : set : debug = 0 and register session
        session_register("");

            $this->Session->write('test',"test1");

                echo $this->Session->read('test');
        }
        return ;
    }

This code is outdated since 2001-2002

To store the data in the session you should use:

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

To get the data stored in the session use:

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

Where name is the session variable name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM