Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter authentication before every controller and action

I am writing a web application using codeigniter.
I want to authenticate the privilege of our users before they access the page.
Actually nearly all controller action except the log in page need to call the model and use

$this->Users->validate($username, $password)

I want to make it general for every controller. Do I need to inherit the controller class? How could i do that?

like image 674
Cato Yeung Avatar asked May 07 '26 08:05

Cato Yeung


1 Answers

We have a project using Codeigniter and the way we are doing it :

When you have a new controller :

class xxxx extends MY_Controller { }

And Inside the MY_Controller class

function __construct() {
 // do your validations
}
like image 94
Tarek Avatar answered May 10 '26 02:05

Tarek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!