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

  • SEARCH
  • Home
  • 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 8404665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:39:24+00:00 2026-06-09T22:39:24+00:00

I am using cakephps Auth Component to login to my site. When I correctly

  • 0

I am using cakephps Auth Component to login to my site. When I correctly enter in my username and password, it will log me in. Then when I use loggedIn() to check that I am logged in, it is very inconsistent in returning true.
This is my AppController where I set loggedIn() to a variable to use later:

<?php

App::uses('Controller', 'Controller');
App::uses('File', 'Utility');
App::uses('AuthComponent', 'Component');

class AppController extends Controller {
    public $components = array(
        'Session',
        'Auth'=>array(
            'loginRedirect'=> array('controller'=>'users', 'action'=>'index'),
            'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'),
            'authError' =>"You can't access that page",
            'authorize'=> array('Controller')
        )

    );
    //determines what logged in users have access to
    public function isAuthorized($user){
        return true;
    }
    //determines what non-logged in users have access to
    public function beforeFilter(){
        $this->Auth->allow('index','view');
        $this->set('logged_in', $this->Auth->loggedIn());
        $this->set('current_user', $this->Auth->user());
    }


}

And here is a bit of my code where I use ‘logged_in’

<?php if($logged_in): ?> //this only returns true some of the time
      Welcome <?php echo $current_user['username']; ?>. <?php echo  $this->Html->link('Logout', array('controller'=>'users', 'action'=>'login')); ?>

<?php else: ?>
   <?php echo  $this->Html->link('Login', array('controller'=>'users', 'action'=>'logout')); ?>
<?php endif; ?>

And here is my login():

public function login(){
    if($this->request->is('post')){
        if($this->Auth->login()){  //this returns true every time
            $this->redirect($this->Auth->redirect());

        }else{
            $this->Session->setFlash('Your username and/or password is incorrect');
        }
    }

}

I have tried calling $this->Auth->loggedIn() instead of using $logged_in but I get the error that the Auth Helper cannot be found.
Please let me know if there is any more information needed to answer my question.

  • 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-09T22:39:25+00:00Added an answer on June 9, 2026 at 10:39 pm

    Move these lines to beforeRender()

        $this->set('logged_in', $this->Auth->loggedIn());
        $this->set('current_user', $this->Auth->user());
    

    Besides that, nothing seems wrong with your code.
    The comment that Auth->login() would always return true only happens when you pass any argument to the login() method, which the code you show doesnt have though.

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

Sidebar

Related Questions

I have a CakePHP website with its own login system using the Auth component.
I am using CakePHP 2.0's integrated Auth component. I have the following tables :
I'm using CakePHP's Auth component and I'm wondering whats the best way to allow
I'm Using CakePHPs standard Auth mechanism, but I have some problems with that. Everytime
I'm using CakePHP's Auth component and it's in my app_controller.php . Now I want
I am using cakephp auth Plugin . After login what happening is . The
I have built a very simple CakePHP website using the Auth component and have
I am making one CakePHP project with Auth component. When I log in I
I am sending email using cakephps email function. The email sends correctly but it
I am having issues accessing session information upon login. I am using Nice Auth

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.