Stupid php question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Stupid php question (/showthread.php?tid=3493) |
Stupid php question - El Forum - 10-05-2007 [eluser]Aaron L.[/eluser] Hi guys, I am trying to write an IF statement which redirects users to the login if they are not one of two types of users (based on session info). Here is what I have: Code: $user_type = $this->session->userdata('user_type'); Why is it that this doesn't work? If the user is a teacher, it skips the redirect but if the user is a school_admin, it sends them to login again. A little help? Stupid php question - El Forum - 10-05-2007 [eluser]Michael Wales[/eluser] Are you sure your cookie has the proper value stored? Try echoing that value out when they are supposed to be a school admin and see if it really reads "school_admin" Also, you could try segregating your conditionals, although I don't think it will make a difference: Code: if (($user_type != "teacher") || ($user_type != "school_admin")) { Finally, why not reverse your logic? I'll assume you have another user_type named "student": Code: if ($user_type == "student") { Stupid php question - El Forum - 10-05-2007 [eluser]ELRafael[/eluser] how are you setting the session? i've some stranges problems with session one day past, and the solution was in set_userdata() that i writted wrong. Stupid php question - El Forum - 10-05-2007 [eluser]Aaron L.[/eluser] Hi guys, Thanks for the replies. I tried echoing the user_type and it indeed said that I was a school_admin. As for wrapping the statements in (), I tried that too to no avail. I guess I'll have to resort to using the reverse logic idea of if($user_type =='student'). Thanks for your input! I appreciate it. Aaron Stupid php question - El Forum - 10-05-2007 [eluser]mironcho[/eluser] Aaron L. You are using OR - use AND instead In your IF statement you are saying "if it is not teacher or it is not school_admin" - so it always is not teacher or school_admin... Stupid php question - El Forum - 10-05-2007 [eluser]Unknown[/eluser] $user_type = $this->session->userdata('user_type'); if($user_type != "teacher" && $user_type != "school_admin") { redirect('login'); } should work. Stupid php question - El Forum - 10-05-2007 [eluser]CI Auke[/eluser] correct... the && (AND) should work. With these kind of statements i always work with the switch statement... like: Code: switch($user_type): |