I have been working with CodeIgniter for couple of days and I love it. For a beginner it`s a great framework for creating web applications.
I`m using Tank auth to set up login system and so far I have managed to get same thing done.
But there is one thing that I can not understand. I`ve been studying Tank auth code and googled but still can not ger around this very simple problem - how do I protect my websites content from unregistered users? What is the method used in CodeIgniter for that?
Lets say for example I have a controller Products with method show. By typing www.mywebsite.com/index.php/products/show I get to see them all in my website. Now how do I forbid unregistered users to access(see) my products?
I do understand that this most likely is silly question but I just can not move on without decent understanding about this. While it is fundamental google does not have the answer... (or I dont know how to ask precisely)
Assuming you have tank auth installed and configured correctly, you can simply redirect someone to the login screen if they aren't already logged in for any particular controller function.
if (!$this->tank_auth->is_logged_in()) redirect('auth/login');
If you use that at the start of any function it ensures only logged in users can load it, because any other user will be redirected away. Likewise, if you want to lock an entire controller off, just place that in the constructor.
The Welcome Controller that comes bundled with Tank Auth shows a good example of it, because only logged in users can see the "you are logged in now" page.