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 8490079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:00:35+00:00 2026-06-10T22:00:35+00:00

I am using CakePHP 2x with Auto-Login component. The problem is, I can write

  • 0

I am using CakePHP 2x with Auto-Login component. The problem is, I can write the stuff but, I am not sure how to implement it to read and authorize. When user arrives at the page, he still has the cookie in his browser but, how do I authorize it?

My Login script:

public function login() {
        if ($this->Auth->user('id')) {
            $this->redirect(array('action' => 'dashboard'));
        }
        if($this->request->data['User']['auto_login']):
        $this->AutoLogin->write($this->request->data['User']['username'],
                $this->request->data['User']['password']);
        endif;

        if ($this->request->is('post')) {
            if ($this->Auth->login( )) {
                //$this->redirect(array('controller' => 'users', 'action' => 'dashboard'));
                return $this->redirect($this->Auth->redirect( ));
            }
            else 
            {
                $this->Session->setFlash(__('Username or Password is incorrect'), 'default', array( ), 'auth');
            }
        }
  • 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-06-10T22:00:37+00:00Added an answer on June 10, 2026 at 10:00 pm

    This should be something like:

    public function login()
    {       
        if ($this->request->is('post'))
        {
            if ($this->Auth->login())
            {               
                if ($this->request->data['User']['persist'] == '1')
                {
                    $cookie = array();
                    $cookie['username'] = $this->data['User']['USER_LOGINNAME'];
                    $cookie['password'] = $this->data['User']['USER_PASSWORD'];
                    $this->Cookie->write('Auth.User', $cookie, true, '+4 weeks');
                }
                $this->redirect($this->Auth->redirect());
            }
            else
            {
                $this->Session->setFlash('Your username or password was incorrect.', 'default/flash-error');
            }
        }
        else
        {
            $user = $this->Auth->user();
            if (empty($user))
            {
                $cookie = $this->Cookie->read('Auth.User');                             
                if (!is_null($cookie)) 
                {
                    $user = $this->User->find('first', array('conditions' => array('USER_LOGINNAME' => $cookie['username'], 'USER_PASSWORD' => AuthComponent::password($cookie['password']))));
                    if ($this->Auth->login($user['User'])) 
                    {
                        $this->Session->delete('Message.auth');
                        $this->redirect($this->Auth->redirect());
                    }
                    else 
                    { 
                        $this->Cookie->delete('Auth.User');
                    }
                }
            }
            else
            {
                $this->redirect($this->Auth->redirect());
            }
        }
    }
    

    This gives you the idea of how to achieve the same task, however, I used form fields according to my DB Structure.

    Kindly change the form fields according to your DB Structure.

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

Sidebar

Related Questions

Using CakePHP 1.3.6 I'm sure I may have to add code and examples, but
I'm using CakePHP to produce a Facebook application (though the problem is not Facebook
hi i am using cakephp for my project but i am fetching problem when
I am using CakePHP. I created an external class which is not a model
I am using CakePHP 2.1 and trying to upload files into server. I can
I am using cakephp auth Plugin . After login what happening is . The
I have a problem when using CakePHP HABTM. I have the following models. class
I'm using Set class of Cakephp to format the find returned array but cannot
I am using cakePHP and I am trying to get the paginator component to
I'm using cakephp 2.1 and cakedc search plugin. The thing is I can't glue

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.