简体   繁体   中英

CakeSession::write() Not working on remote server, but works fine on localhost

I have this code which authenticate user for login and it works fine on localhost but on remote server does not work. It only loads and stays on the login page. But when username or password is wrong it gives the error message well.

if($this->request->is('post')){
            $data = $this->request->data;
           $password = sha1($data['password']);
            $email = $data['email'];

            $authUser = $this->User->find('first', array('conditions' => array('User.email' =>
            $email, 'User.password' => $password)));
            if(count($authUser) > 0){

                CakeSession::write('loggedInUser', $authUser['User']['id']);
                CakeSession::write('loggedInName', $authUser['User']['first_name'].' '.$authUser['User']['last_name']);
                CakeSession::write('verStatus', $authUser['User']['verified']);

                if(null != CakeSession::read('loggedInUser')){

                   $this->redirect('/shop');

                }

            }else{
               $loginError = 'Invalid username or password';
                $this->set('invalid', $loginError);
            }
        } 

Can any one have an idea of what is happening? My Cakephp version is 2.5.4

Try using

$this->Session->write('loggedInName',$authUser['User']['first_name'].' '.$authUser['User']['last_name']);

same for session->read .

Like this . And check PHP version at both sides.

Read This

Also clear cache , temp folder , switch core.php -> debug to 2 , then again to 0.

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

我认为必须使用以上语法。

That problem can be from file session storing permissions on dedicated server, for skip this issue you can save session in to database, please follow the link below and look at my answer (about configure session and create new table for it). Session Permission Denied on AWS after setting up Cake php. Hope it will be helpful for you.

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