how to create premission ..! - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: how to create premission ..! (/showthread.php?tid=25070) |
how to create premission ..! - El Forum - 11-30-2009 [eluser]Unknown[/eluser] i mean when i login as user , i cant go to the admin page also i type the link true , example : my admin page like : http://localhost/exam/index.php/admin/admincp when i am a normal user it will return some false information like : you are not admin ..! something like this ..! and when i login as admin , i can come in ..! i have trie use session put in the admin controller Code: class admin extends controller i know i was wrong , because when i type the url i can come in the admin page also i'm just a normal user ..! please help me to fix this problem ..! Thank so much ..! how to create premission ..! - El Forum - 11-30-2009 [eluser]überfuzz[/eluser] What's the problem, writing to the session array? If you're having problems with the session class you should read about it in the all mighty user_guide. how to create premission ..! - El Forum - 11-30-2009 [eluser]Unknown[/eluser] my problem is i can not set the permission for the admin page , it mean anyone can login in the admin control , and edit everthing ..! please teach me how to set the permission just admin can login ,user can not login although they know the link come to the admin page ..! how to create premission ..! - El Forum - 12-01-2009 [eluser]Flemming[/eluser] You need a 'login' controller. Simply set a session inside your login controller (if the login was successful) like so: Code: $this->session->set_userdata('admin_logged_in', TRUE); Then in your 'admin' controller, in the constructor() you can check if that session DOESN'T exist: Code: if(!$this->session->userdata('admin_logged_in')) redirect('/login'); that will redirect anyone who doesn't have the 'admin_logged_in' session back to the login controller BEFORE they are able to access any of the admin methods. does that help? how to create premission ..! - El Forum - 12-01-2009 [eluser]überfuzz[/eluser] [quote author="Flemming" date="1259688630"]... Then in your 'admin' controller, in the constructor() you can check if that session DOESN'T exist: Code: if(!$this->session->userdata('admin_logged_in')) redirect('/login'); [/quote] I think he's looking for a way to give different permissions. Code: if($this->session->userdata('access_level') < $access_level_needed) redirect('/login'); how to create premission ..! - El Forum - 02-18-2010 [eluser]livestrong[/eluser] [quote author="Flemming" date="1259688630"]You need a 'login' controller. Simply set a session inside your login controller (if the login was successful) like so: Code: $this->session->set_userdata('admin_logged_in', TRUE); Then in your 'admin' controller, in the constructor() you can check if that session DOESN'T exist: Code: if(!$this->session->userdata('admin_logged_in')) redirect('/login'); that will redirect anyone who doesn't have the 'admin_logged_in' session back to the login controller BEFORE they are able to access any of the admin methods. does that help?[/quote] Hi there, I tried to use this method, but failed. It seems that admin methods are executed BEFORE the redirect. What am I doing wrong? Here is the code: Code: class Cities extends Controller { I'm trying to get access to one of the Cities class methods. And I'm getting it even without being logged in. Please advice. how to create premission ..! - El Forum - 02-19-2010 [eluser]Flemming[/eluser] that looks fine to me, why don't you try echoing out $this->session->userdata('user_id') inside your index method to see what it contains? how to create premission ..! - El Forum - 02-19-2010 [eluser]livestrong[/eluser] I've already checked administrator's id. It is correct. Maybe I'm not very clear in my description. When I try to launch any method from the Cities class without being logged in, I'm redirected to the root. This is correct. BUT the method that I was accessing is also performed. I think it shouldn't be. Have no idea how to proceed... |