dongzhi2887 2013-06-16 15:18
浏览 26

cookie没有保存Cakephp

Cake is not saving the cookie, at least not that I can see, and when I revisit the page I am not auto logged in.i actually want to implement the 'remember me functionality '.i am using this component https://github.com/ceeram/Authenticate/wiki/Set-Cookie

here is my code

login.ctp

echo $this->form->create();

echo $this->form->input('email');
echo $this->form->input('password');

 <?php echo $this->Form->checkbox('remember_me', array('hiddenField' => false,'name' =>   'remember_me'));?>
 echo $this->form->end('submit');
 ?>

UserController

<?php
  class UsersController extends AppController {

 public $components = array('Cookie');

 public function beforeFilter() {
    parent::beforeFilter();

    $this->Cookie->type('rijndael');

    $this->Security->requireSecure('login');// for security
    $this->Auth->authenticate = array(
        'Authenticate.MultiColumn' => array(
            'fields' => array(
                'username' => 'email',
                'password' => 'password'
            ),
            'columns' => array('email', 'mobileNo'),
            'userModel' => 'User',
        )
    );
}


public function index(){

}


public function login() {
    $this->layout='userdefault';
    if ($this->request->is('post')) {

        //$this->Auth->logout();
        $cookie = $this->Cookie->read('Auth.User');
        debug($cookie);
        if ($this->Auth->login()) {
            $this->_setCookie($this->Auth->user('id'));
            $this->redirect('/users/controlpanel');

        } else {
            $this->Session->setFlash('Incorrect Email/Password Combination');
        }
    }
}
  protected function _setCookie($id) {
    if (!$this->request->data('User.remember_me')) {
        return false;
    }
    $data = array(
        'username' => $this->request->data('User.email'),
        'password' => $this->request->data('User.password')
    );
    $this->Cookie->write('User', $data, true, '+1 week');
    return true;
}
public function logout() {
    $this->redirect($this->Auth->logout());
}
public function controlpanel(){
    $this->layout='controlpaneldefault';

   }

  }
?>

and also tell me how can i check or debug the cookie to check that whether my cookie saving or not or if debugging is not possible then tell me how can i set the name of the cookie so i go in the browser cookies and search the cookie with name

  • 写回答

1条回答 默认 最新

  • doulong2782 2013-06-16 18:04
    关注

    insert exit(); after debug($cookie); for check cookie data.

    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真