title: CakePHP remember me cookie function returns Illegal string offset
body: <p>I am trying to implement remember me function in CakePHP. At times (like every 2-3 logouts) when a user logout it returns: illegal string offset 'username' and 'password' in line 84 (marked below in AppController codes), while debug in line 80 returns $cookie to be 'deleted'. I don't know how to check if the cookie is working but I presume this means it's not.</p>
  
  <p>Users/login.ctp:</p>
  
  <pre><code>&lt;?php 
  echo $this-&gt;Form-&gt;create('User', array(
      'url' =&gt; array(
      'controller' =&gt; 'users', 
      'action' =&gt; 'login'),
      'class' =&gt; 'form-signin', 'inputDefaults' =&gt; array(
          'label' =&gt; false, 'div' =&gt; false)
  ));
  
  echo $this-&gt;Form-&gt;input('User.username', array(
      'placeholder' =&gt; 'username', 
      'class' =&gt; 'form-control'
  )); 
  
  echo $this-&gt;Form-&gt;input('User.password', array(
      'placeholder' =&gt; 'password', 
      'class' =&gt; 'form-control', 
      'type' =&gt; 'password'
      )); 
  ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;checkbox('User.remember_me', array('label' =&gt; 'remember me')); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;label('User.remember_me', 'Remember Me'); ?&gt;
  
  &lt;?php
  $options = array(
      'label' =&gt; 'Login',
      'class' =&gt; 'btn btn-default', 
      'div' =&gt; array(
      'class' =&gt; 'form-group')
  );
  echo $this-&gt;Form-&gt;end($options);
  ?&gt;
  </code></pre>
  
  <p>UsersController:</p>
  
  <pre><code>public function login() {
  
  if ($this-&gt;Session-&gt;read('Auth.User')) {
      $this-&gt;Session-&gt;setFlash(__('You are already logged in!'), 'alert_box', array('class' =&gt; 'alert-warning'));
          return $this-&gt;redirect($this-&gt;referer());
  }
  
  if ($this-&gt;request-&gt;is('post')) {
      if ($this-&gt;Auth-&gt;login()) {
          //Did they select the remember me checkbox?
          if ($this-&gt;request-&gt;data['User']['remember_me'] == 1) {
              //Remove "remember me checkbox"
              unset($this-&gt;request-&gt;data['User']['remember_me']);
  
              //Write the cookie
              $this-&gt;Cookie-&gt;write('remember_me_cookie', $this-&gt;request-&gt;data['User']['username'], true, '2 weeks');
          }
  
          $this-&gt;Session-&gt;setFlash(__('You are logged in!'), 'alert_box', array('class' =&gt; 'alert-success'));
          if ($this-&gt;Session-&gt;read('lastUrl')) {
              return $this-&gt;redirect($this-&gt;Session-&gt;read('lastUrl'));
          } else {
              return $this-&gt;redirect($this-&gt;Auth-&gt;redirect());
          }
      }
      $this-&gt;Session-&gt;setFlash(__('Your username or password was incorrect.'), 'alert_box', array('class' =&gt; 'alert-danger'));
  }
  }
  </code></pre>
  
  <p>AppController: </p>
  
  <pre><code>public $components = array(
      'Acl',
      'Auth' =&gt; array(
          'authorize' =&gt; array(
              'Actions' =&gt; array('actionPath' =&gt; 'controllers')
          ),
          'unauthorizedRedirect' =&gt; '/posts'
      ),
      'Session',
      'Cookie'
  );
  
  public $uses = array('User');   
  
  public function beforeFilter() {
      // Set Cookie Options
      //$this-&gt;Cookie-&gt;key = 'qSI232qs*&amp;sXOw!adre@34SAv!@*(XSL#$%)asGb$@11~_+!@#HKis~#^';
      $this-&gt;Cookie-&gt;httpOnly = true;
  
      if (!$this-&gt;Auth-&gt;loggedIn() &amp;&amp; $this-&gt;Cookie-&gt;read('remember_me_cookie')) {
          $cookie = $this-&gt;Cookie-&gt;read('remember_me_cookie');
          $this-&gt;loadModel('User');
          $user = $this-&gt;User-&gt;find('first', array(
              'conditions' =&gt; array(
                  'User.username' =&gt; $cookie['username'] //line 84
              )
          )); 
          if ($user &amp;&amp; !$this-&gt;Auth-&gt;login($user['User']['username'])) {
              $this-&gt;redirect('/users/logout'); // Destroy Session &amp; Cookie
          }
      }       
  }
  </code></pre>