Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:09:27+00:00 2026-05-28T15:09:27+00:00

In my users controller I am trying to put in place the remember me

  • 0

In my users controller I am trying to put in place the remember me functionality on login. IT seems pretty simple set a cookie look for the cookie when the user visits the login page and if it exists log them in. However, 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.

To test this I have the following code:

$cookie=$this->read('Auth.User');
if(empty($cookie) and !empty($this->data)){
    if($this->Auth->login()) {
        if(!empty($this->data['User']['remember_me'])){
            $cookie = array('id' => $this->Auth->user('id'),
            );
            $expires=strtotime($this->appConfigurations['remember_me'],time());
            $this->Cookie->write('Auth.User', $cookie, false, $this->appConfigurations['remember_me']);
        }
    }
}

Now right after I set this cookie I can place a $this->cookie->read(‘Auth.User’); and get the value of this cookie, however it does not show up in the browsers (Chrome, FireFox) cookie list.

If I use plain PHP cookies, via setcookie() I can see the cookie but of course the Cake Cookie read does not work with those cookies. What should I look for to resolve this issue?

I did find a work around, but I don’t like it because it just bypasses the framework. I found out how cake is creating the cookies and for these cookies I use cakes cookie creation algorithm in my code and use setcookie() to do the setting. Just for anyone else that may want or need to use the work around:

$cookieValue=$this->Auth->user('id');
setcookie('CakeCookie[Auth][User]',$cookieValue,$expires,'/');

Now you can use cakes cookie component to read the value. There is more you have to change if your value is an array, read through the cookie.php code to see what you would need to do. Also I left out the encryption that too can be found in the cookie.php and your apps settings. For this issue I do not need array values since I am only store the users ID. and I did put in place encryption unlike above.

I would still like to know why the component is not working though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:09:28+00:00Added an answer on May 28, 2026 at 3:09 pm

    The following login action works well for me :

    function login() {
        $cookie = $this->Cookie->read('Auth.User');
        debug($cookie); // Just a test
        if ($this->Auth->user('id')) {
            if(!empty($this->data)) {
                $cookie = array(
                    'username' => $this->data['User']['username'],
                    'password' => $this->data['User']['password']
                );
                $this->Cookie->write('Auth.User', $cookie, false, '+2 weeks');
            }
            $this->redirect('/');
        }
        elseif (!empty($cookie)) {
            if ($this->Auth->login($cookie)) {
                $this->redirect('/');
            }
        }
    }
    

    Does it work on your side ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller user with a method login For some reason, when I
I am trying to build a very simple rails application. When user submits a
I'm trying to redirect users that login to their profile page but get the
I'm trying to put together a page whereby a user can upload a file,
I am trying to unit test a controller action that uses UpdateModel but I
I have an entries controller that allows users to add contact information the website.
I wrote a device controller (rs232) and it is being used successfully, however users
I have a form which users must fill out and submit. The controller action
I have a simple UserControl for database paging, that uses a controller to perform
Currently my controller lets a user submit muliple links at a time. It collects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.