Welcome Guest, Not a member yet? Register   Sign In
Redirect inside Constructor NOT WORKING
#4

(10-06-2019, 08:42 PM)kilishan Wrote: Redirect now returns a class instead of just setting headers. You cannot return an instance of another class while instantiating a different class in PHP.

Check out Controller Filters

Thank you Sir !

I am sooo used to use CI3 that I forgot a little bit about the PHP itself...

I am very eager to use Myth Auth in my projects... But, meanwhile, I am using BenĀ“s Ion Auth 4 ...

The point is that I want to make my code cleaner and I am checking for login in the constructor or in the baseController.

Do you have any tips about the best way of doing it ?

I am doing like this:

PHP Code:
    public function checkLoggedIn()
    {
        
//Checks if user is LOGGED IN 
        
if (!$this->ionAuth->loggedIn()) :

            if (
$this->request->isAJAX()) :

                
$data = [
                    
's' => false//Success = False
                    
'm' => 'Not Logged In' //Message to be returned
                
];

                
header("HTTP/1.1 401 Unauthorized"); //Status Code 401 = Unauthorized
            
                
echo json_encode($data);

                exit;

            endif;

            
header("Location: /auth");

            exit;

        endif;
    } 
Reply


Messages In This Thread
RE: Redirect inside Constructor NOT WORKING - by Poetawd - 10-07-2019, 12:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB