codeigneter sessions |
[eluser]hamzakhan[/eluser]
i have 5 or 6 controllers. should i put this code on each controller or is there is any short smart way to put in one file and use every where. //// login check if ($this->session->userdata('logged_in') == FALSE) { redirect('admin/Login'); }
[eluser]Ripe[/eluser]
You could create a hook but you would also need to tell it when not to redirect, like you wouldn't want it to redirect on the login page because that would create a loop. http://ellislab.com/codeigniter/user-gui...hooks.html My logged in hook looks like this: Code: function protected_pages()
[eluser]überfuzz[/eluser]
I see two alternatives. 1. Make an auth library with a method called redirect(). Make it look for and validate the user/session. Then you can use it where ever you want. Code: $this->load->library('Auth'); Code: if(!$this->session->userdata('logged_in'))
[eluser]jedd[/eluser]
[quote author="hamzakhan" date="1259874075"] should i put this code on each controller or is there is any short smart way [/quote] The really smart way is to read the [url="/wiki/FAQ"]FAQ[/url] and look for the question that says 'I keep repeating lumps of code, is there some other way ...'.
[eluser]hamzakhan[/eluser]
thanks for your suggestion ------------ i am new in codeigneter so bit difficult to understand can anyone give me proper example |
Welcome Guest, Not a member yet? Register Sign In |