wezze Posted June 24, 2012 Share Posted June 24, 2012 ok im having trouble with the session thing this is my include file for my side menu every lvl got other links to show but it only displays the if( $session->logged_in part it ignores the rest. So my question is what im i missing or doing wrong here? <? /** * Users can see logged_in * Members --> lvl5 * Mods --> lvl7 * Admin/lvl9 isAdmin */ if( $session->logged_in){ echo "<h3>Menu</h3>"; echo "<li><a href=\"userinfo.php?user=$session->username\">My Account</a></li>" ."<li><a href=\"useredit.php\">Edit Account</a></li>"; echo "<p> </p>"; if( $session->isUserlevel(5)){ echo "<li><a href=\"filmen_leden.php\">Filmen</a></li>"; if( $session->isUserlevel(7)){ echo "<li><a href=\"links.php\">links</a></li>" ."<li><a href=\"upload_kalender/upload.form.php\">upload kalender</a></li>"; if($session->isAdmin()){ echo "<li><a href=\"../livre d'or/admin/index.php\">livre d'or</a></li>" ."<li><a href=\"../gastenboek/admin/index.php\">Gastenboek</a></li>" ."<li><a href=\"admin/index.php?id=1\">Admin Center</a></li>"; } echo "<p> </p>" ."<li><a href=\"process.php\">Logout</a></li>"; }}} ?> thx Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/ Share on other sites More sharing options...
Mahngiel Posted June 24, 2012 Share Posted June 24, 2012 I assume the problem is because you are checking if the user's level is exactly 5, 7, or admin. You need to set up your user levels to be inclusive of the lower privileges as well - if that fits your scheme. The way you have it now, if you are ?SuperModerator? and your level is 7, you will return false for being Userlevel 5 ?Moderator? There are several different approaches to privilege levels. You could [*] check for permission levels based on actions (can edit, can post, can delete, etc) where as user levels raise, so do the perms. [*] check if user level is >= 5/7/9, which would return true for admin to see mod privs [*] create a perms table with boolean rows for things like: is_banned, is_member, is_mod, is_supermod, is_admin, is_superadmin and change your functions accordingly. Bottom line, no matter how you do it, you need to give your high priv'd users access to lower level perms. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356610 Share on other sites More sharing options...
wezze Posted June 24, 2012 Author Share Posted June 24, 2012 thats exactly what i want that the admin/lvl9 can see everyting and a user as good as nothing. i dont rlly understand this option check if user level is >= 5/7/9, which would return true for admin to see mod privs how do i approach this? or is it possible to redirect each lvl to another page? thanks Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356615 Share on other sites More sharing options...
Mahngiel Posted June 24, 2012 Share Posted June 24, 2012 how are you determining your permission levels? Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356619 Share on other sites More sharing options...
wezze Posted June 24, 2012 Author Share Posted June 24, 2012 in my admin cp i chose who get which lvl. i just modified last post Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356620 Share on other sites More sharing options...
Mahngiel Posted June 24, 2012 Share Posted June 24, 2012 or is it possible to redirect each lvl to another page? Why? That's like... quadruple the work! Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356635 Share on other sites More sharing options...
wezze Posted June 24, 2012 Author Share Posted June 24, 2012 Well not rlly i only need to lvl the members of the club non members stay at low lvl. So i only need to make 1 a mod so he can help me with uploads of pics ect... and then the rest members ,so that the members cant mess around. I need to activate acounts so i might aswell asign a lvl while im busy its not that we got 100 members (yet). Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356638 Share on other sites More sharing options...
Mahngiel Posted June 24, 2012 Share Posted June 24, 2012 Nah man. You present the same page template to everybody. When it comes to deleting things or performing mod/admin actions, you draw those in with conditional statements. One page - that's it! Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356670 Share on other sites More sharing options...
wezze Posted June 25, 2012 Author Share Posted June 25, 2012 ok but how? thx Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356856 Share on other sites More sharing options...
Mahngiel Posted June 25, 2012 Share Posted June 25, 2012 "How" is part of the programmatic puzzle that is your job as the developer to figure out. The answers to that lie in your application, how it's going to be used, what can be accomplished, and how you're going to accomplish it. Foremost, you need to rectify your establishment of user privileges - ensuring that the top can see all the way down and your levels between A and Z have the proper privileges. You've gotten half-way there already, but you need to make some modifications that I eluded to previously. Once you have proper privs established, then you can assign permissions. Let's say, for instance, you have a news blog up. This news blog permits registered users to post comments on the blog. And you've already established an admin section for writing and editing the articles. Since every blog post will follow the same template, you only need one view file, right? This has things like the title, a summary, the body, and an area for comments. So, based on the URI your visitors browse to, the proper article gets loaded with database info. Now, since you have varying amounts of privileges, there are different things that people can do while on this page. Admin may get a special link that directs them to the admin section where they can edit the post // moderators may get a special icon that allows them to delete a comment // and banned users may not get to even comment. There's no need for new pages, you'll just draw in special elements depending on privilege level. It's your job to figure out who, what, where, when, and how. If you get lost trying to accomplish something, this forum has many dedicated and helpful members. If you want somebody to do this for you, you'll need to visit the freelancer section and be prepared to pony up some cash. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356862 Share on other sites More sharing options...
wezze Posted June 25, 2012 Author Share Posted June 25, 2012 i dont need any1 to do it for me i only need a little puch in the right direction. ive been google-ing like hell on this subject and cant find anything thats why i posted here. i rlly dont get why the script stops at the first if session. thx Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356865 Share on other sites More sharing options...
Mahngiel Posted June 25, 2012 Share Posted June 25, 2012 I explained it to you in my first reply, but let's look at it again. <?php if( $session->isUserlevel(5)){ // do something if( $session->isUserlevel(7)){ // do something if($session->isAdmin()){ // do something } } } As you can see, you are checking levels backwards. You are checking that the user level is 5. This obviously will not work because if the value is NOT 5 the function returns as false and doesn't even bother to look down the road. So the check for level 7 is never performed, and nor is the check for admin status. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356867 Share on other sites More sharing options...
wezze Posted June 25, 2012 Author Share Posted June 25, 2012 ok but if i do it otherwise and the user isnt admin the script wont bother to look for 7, 5 ect and if i would use elseif would that do the trick? like <?php if( $session->Logged_in){ // do something if( $session->isAdmin()){ // do something elseif($session->isUserlevel(7)){ // do something } } } thx Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356873 Share on other sites More sharing options...
Mahngiel Posted June 25, 2012 Share Posted June 25, 2012 I assume the problem is because you are checking if the user's level is exactly 5, 7, or admin. You need to set up your user levels to be inclusive of the lower privileges as well - if that fits your scheme. The way you have it now, if you are ?SuperModerator? and your level is 7, you will return false for being Userlevel 5 ?Moderator? There are several different approaches to privilege levels. You could [*] check for permission levels based on actions (can edit, can post, can delete, etc) where as user levels raise, so do the perms. [*] check if user level is >= 5/7/9, which would return true for admin to see mod privs [*] create a perms table with boolean rows for things like: is_banned, is_member, is_mod, is_supermod, is_admin, is_superadmin and change your functions accordingly. Bottom line, no matter how you do it, you need to give your high priv'd users access to lower level perms. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356875 Share on other sites More sharing options...
wezze Posted June 25, 2012 Author Share Posted June 25, 2012 check if user level is >= 5/7/9, which would return true for admin to see mod privs how do i approach this? <?php if( $session->=(3)(5)(7)){ // but then it doesnt matter what lvl they are thell all see the same here? if( $session->isAdmin()){ // do something } } thx Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356880 Share on other sites More sharing options...
Mahngiel Posted June 25, 2012 Share Posted June 25, 2012 No man, that's not going to work. Why don't you post your isUserlevel() and isAdmin() functions and we can baby step through this. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356881 Share on other sites More sharing options...
wezze Posted June 25, 2012 Author Share Posted June 25, 2012 <? if($session->logged_in){ echo "<h3>Menu</h3>"; echo "<li><a href=\"userinfo.php?user=$session->username\">Mijn Account</a></li>" ."<li><a href=\"useredit.php\">Instellingen</a></li>"; echo "<p> </p>"; if($session->isAdmin()){ echo "<li><a href=\"filmen_leden.php\">Filmen</a></li>" ."<li><a href=\"links.php\">links</a></li>" ."<li><a href=\"upload_kalender/upload.form.php\">upload kalender</a></li>" ."<li><a href=\"../livre d'or/admin/index.php\">livre d'or</a></li>" ."<li><a href=\"../gastenboek/admin/index.php\">Gastenboek</a></li>" ."<li><a href=\"admin/index.php?id=1\">Admin Center</a></li>"; } echo "<p> </p>" ."<li><a href=\"process.php\">Logout</a></li>"; } ?> you mean this? atm its still set for users and admin only. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356884 Share on other sites More sharing options...
Mahngiel Posted June 25, 2012 Share Posted June 25, 2012 No. I want to see <?php function isAdmin() { ... } function isUserlevel() { .. } Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356894 Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2012 Share Posted June 25, 2012 This is going to seem rather blunt, but you're trying to get other people to blindly throw possible solutions at some code that you didn't write, don't understand, the author no longer supports, and has terrible documentation. It may be time to find a different application that actually works. Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356900 Share on other sites More sharing options...
wezze Posted June 25, 2012 Author Share Posted June 25, 2012 No. I want to see <?php function isAdmin() { ... } function isUserlevel() { .. } cant find it :s i geusse ill look for something else or try to find some tutorials thx anyway Quote Link to comment https://forums.phpfreaks.com/topic/264686-if-session-problem/#findComment-1356913 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.