Simple Acl |
hi , when an user log into my site a set 2 session variable :
$_SESSION['user_id] and $_SESSION['role_id'] to redirect every view if the user aren't logged i try to insert an if in the construct : Code: public function __construct() { But the browser tell me that ther'are too many redirect . Why ?
(09-02-2017, 03:41 AM)pippuccio76 Wrote: hi , when an user log into my site a set 2 session variable : you have a redirect loop. the __construct is in the user class? edit: if you not loged in. the redirect looks like user/index to user/index to user/index
(09-02-2017, 03:45 AM)Paradinight Wrote:(09-02-2017, 03:41 AM)pippuccio76 Wrote: hi , when an user log into my site a set 2 session variable : The construct is in User controller. If i am not logged the variable $_SESSION['user_id'] not isset and i redirect to user/login
(09-02-2017, 03:51 AM)pippuccio76 Wrote:(09-02-2017, 03:45 AM)Paradinight Wrote:(09-02-2017, 03:41 AM)pippuccio76 Wrote: hi , when an user log into my site a set 2 session variable : PHP Code: if(!isset($_SESSION['user_id'])){ the construct will be called automatically. it check always the value and redirect you to the same constructor and it will redirect you.
(09-02-2017, 09:51 AM)Paradinight Wrote:(09-02-2017, 03:51 AM)pippuccio76 Wrote:(09-02-2017, 03:45 AM)Paradinight Wrote:(09-02-2017, 03:41 AM)pippuccio76 Wrote: hi , when an user log into my site a set 2 session variable : Then how can i redirect if the user isn't logged ? Must i insert the if statement in every controller's function ? Is there a way to do this more quicly ?
09-03-2017, 03:14 AM
(This post was last modified: 09-03-2017, 03:16 AM by InsiteFX. Edit Reason: Added MY_Controller Code )
Yes, Use a My_Controller and extend all of your Controllers from the MY_Controller
PHP Code: <?php What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |