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

Friday, April 22, 2022

[FIXED] How to redirect each type of user to a different page when access is denied?

 April 22, 2022     authentication, cakephp, cakephp-2.3     No comments   

Issue

In my app I have 3 roles of Users (user, admin, non logged user), and I want to redirect them to different pages when access is denied. How to do that?

In time, what $this->Auth->authorize = array('Controller'); means? I didn't understand this in cake docs.

Thanks all.


Solution

I would have it in a IF statement, but perhaps someone else can suggest a more CakePHP specific method..

if($user === 'Admin') {
   //Admin Redirect
   $redirectController = 'admin';
   $redirectMethod = 'admin_index';
} elseif ($user === 'User') {
   //User Redirect
   $redirectController = 'user';
   $redirectMethod = 'index';
} else {
  //Not logged in
  $redirectController = 'SomeController';
  $redirectMethod = 'someMethod';
}

$this->Auth->unauthorizedRedirect = array(
        'controller' => $redirectController,
        'action' => $redirectMethod 
    );

$this->Auth->authorize = array('Controller'); means that the Authorization is done at the Controller level. I believe you can change where authorization is carried out using this.



Answered By - Chronix3
Answer Checked By - Terry (PHPFixing Volunteer)
  • 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