PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] How to get attempted log-in user name?

 January 17, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

I am using cakephp v3.x

Below is my login function.

public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error(__('Invalid username or password, try again'));
    }
} //public function login()

I am trying to get the username who tried to log in. I tried reading http://book.cakephp.org/3.0/en/controllers/components/authentication.html I am not able to find the API to retrieve the username. How can this be done?


Solution

You will get all details for user :

$user_details = $this->Auth->User();
echo $user_details['username'];


Answered By - Lakhan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing