CodeIgniters session library - how to? |
[eluser]v33s[/eluser]
Hello all, I am new in CodeIgniter and I have a question about CodeIgniters Sessions. Can someone explain me how to start write simple admin login page area? I tried most of complete Authorization Systems but I don`t understand how to implement them in my code. Ok. I have my `admins` MySQL table with -id-name-md5password- columns. On first place in my Contructor, i have that code: Code: $this->load->library(array('session', 'validation')); I would like to check the form values with the database values, if it is correct then make a session. I can extract user from database, but how to make a session, check it if admin is now logged in??? I found in User Guide how to make a session: Code: $newdata = array( And now, what I must change in this array? Replace username with this from database? How to check this session if it is correct? Sorry for my English ![]()
[eluser]Seppo[/eluser]
Well... to login you have to store something on the session... you don't have an email, so, with your db columns you can do Code: $this->db->where('username', $this->input->post('username')); Then, on an admin-page you have to check any of those values... Code: $this->load->library('session');
[eluser]v33s[/eluser]
Hello! Thanks a lot Seppo. That`s I need! Code: if (!$this->session->userdata('is_admin')) Code: array( So I understand it now! ![]() Code: if(!isset($this->session->userdata('is_admin'))
[eluser]Seppo[/eluser]
No... Isset only works with variables (empty is the same). Also the userdata method returns FALSE when it doesn't exists, not NULL. |
Welcome Guest, Not a member yet? Register Sign In |