Problem with user authentication |
[eluser]marcin_koss[/eluser]
I have a problem creating authentication part for my application. Below is the simplified version of my controllers. The idea is that the MY_controller checks if session with user data exists. If it doesn't, then redirects to the index page where you have to log in. MY_controller.php Code: class MY_Controller extends Controller { order.php - main controller Code: class Orders extends MY_Controller { what is happening is that the browser is telling me that "The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete." Does that mean that the redirect is in a loop? I also came across this article where authentication is handled pretty much the same way http://davidwinter.me.uk/articles/2009/0...deigniter/
[eluser]Barry Cogan[/eluser]
Yes that does mean you are caught in an infinite loop. A couple of things to note aswell: you are already loading your URL and Session in the My_Controller. You don't need to load them them again in the Orders controller. Secondly the parent call should read parent::MY_Controller(); for orders.php and parent::Controller(); for MY_Controller.php Makes for easier reading.
[eluser]marcin_koss[/eluser]
Barry Cogan, I get this error after adding your corrections to the parent call. "Fatal error: Call to undefined method MY_Controller::my_controller()"
[eluser]marcin_koss[/eluser]
Ok, I fixed that. I also had to change names for constructors. So now again I'm back in the loop. The way I called the parent method was fine according to OOP in PHP5.
[eluser]Barry Cogan[/eluser]
I'm sure it is. It's more for ease of reading. I assume you have the MY_Controller saved in the application/libraries directory? I have never called multiple views in CI. I call a master view which has the view calls in it. Not sure if that has any bearing on the problem?
[eluser]marcin_koss[/eluser]
Barry Cogan thanks for your help. I solved the issue. I was calling redirect() function from within construct of the same controller which was causing the infinite loop. To make the login authentication work correctly I needed to create a new controller file I could redirect to when the user login session was not set.
[eluser]Barry Cogan[/eluser]
Delighted you got it sorted. Good luck with your project! ![]() |
Welcome Guest, Not a member yet? Register Sign In |