how to create premission ..! |
[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 ..!
[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.
[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 ..!
[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?
[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');
[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.
[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?
[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... |
Welcome Guest, Not a member yet? Register Sign In |