Xtremer360 Posted December 23, 2008 Share Posted December 23, 2008 What I want to do is connect my login script with my control panel in such a way that when the user logs in it checks the database to see if they are an admin and then if they are it loads the correct options available to them and if they aren't then it'll load the non admin options.. Can I get any assistance because I've done research all day with this and no luck. So basically after login at the control panel for admins it'll load all the options 0-5 and if they are non admins it'll only load only 4 & 5. Login script: <?php //if the login form is submitted if(isset($_POST['login'])) { // makes sure they filled it in if(!$_POST['username'] || !$_POST['pass']) { die('You did not fill in a required field.'); } $username = mysql_real_escape_string($_POST['username']); $pass = mysql_real_escape_string($_POST['pass']); $check = mysql_query("SELECT * FROM users WHERE username = '".$username."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.'); } while($info = mysql_fetch_array( $check )) { $pass = md5(stripslashes($_POST['pass'])); $info['password'] = stripslashes($info['password']); //$_POST['pass'] = md5($_POST['pass']); THIS IS DONE IN THE ABOVE STATEMENT //gives error if the password is wrong if ($pass != $info['password']) { die('Incorrect password, please try again.'); } else // if login is ok then we add a cookie and send them to the correct page { $username = stripslashes($username); session_start(); $_SESSION['username'] = $username; $_SESSION['loggedin'] = time(); // Finds out the user type $query = "SELECT `admin` FROM `users` WHERE `username` = '" . $username . "'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $admin = $row['admin']; $_SESSION['admin'] = $admin; } } } else { // if they have not submitted the form ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Language" content="en-us"> <meta name="language" content="en-us"> <title>Backstage V1 Administration Console</title> <link rel=stylesheet href=backstage.css type=css media=screen> <link rel=stylesheet href=backstage_print.css type=css media=print> </head> <body> <div id=login> <form method="POST" action="http://kansasoutlawwrestling.com/other/backstage.php"> <h1>KOW Backstage</h1> <p><label>Username:<br><input type=text name=uname id=log tabindex=1></label></p> <p><label>Password:<br><input type=password name=pword id=pwd tabindex=2></label></p> <p style="text-align: center;"><input type=submit class=button name=submit id=submit value="Login »" tabindex=4></p> </form> </div> </body> </html> <?php } ?> Control Panel: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Language" content="en-us"> <meta name="language" content="en-us"> <title>Backstage V1 Administration Console</title> <link rel="stylesheet" href="backstage.css" type="text/css" media="screen"> <link rel="stylesheet" href="backstage_print.css" type="text/css" media="print"> <script src="prototype.js" type="text/javascript"></script> <script src="scriptaculous.js" type="text/javascript"></script> <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var page = document.cookie.match(/page=[\w][\w\-\.]+;/); if(page != null) { ajaxpage("page", "content"); } else { ajaxpage("home", "content"); } </script> </head> <body> <div id=container> <div class=header> <table cellpadding="0" cellspacing="0" border="0" width="95%"> <tr> <td width=110 align=center></td> <td></td> <td width=40 valign=bottom align=right> <a href="#" onclick="ajaxpage('home', 'content'); return false;">Home</a> | <a href="#" onclick="ajaxpage('logout', 'content'); return false;">Logout</a> | <a target="_blank" href="http://kansasoutlawwrestling.com/phpBB3">Forums</a></td> </tr> </table> </div> <div id=container2> <div id=nav> <?php if(isset($_SESSION['admin'])){ if($_SESSION['admin'] <= 5){ }} ?> <h1>Character</h1> <ul> <li><a href="#" onclick="ajaxpage('bio', 'content'); return false;">Bio</a></li> <li><a href="#" onclick="ajaxpage('allies', 'content'); return false;">Allies</a></li> <li><a href="#" onclick="ajaxpage('rivals', 'content'); return false;">Rivals</a></li> <li><a href="#" onclick="ajaxpage('quotes', 'content'); return false;">Quotes</a></li> </ul> <?php if(isset($_SESSION['admin'])){ if($_SESSION['admin'] <= 4){ }} ?> <h1>Submit</h1> <ul> <li><a href="#" onclick="ajaxpage('roleplay', 'content'); return false;">Roleplay</a></li> <li><a href="#" onclick="ajaxpage('news', 'content'); return false;">News</a></li> <li><a href="#" onclick="ajaxpage('match', 'content'); return false;">Match</a></li> <li><a href="#" onclick="ajaxpage('seg', 'content'); return false;">Seg</a></li> </ul> <?php if(isset($_SESSION['admin'])){ if($_SESSION['admin'] <= 3){ }} ?> <h1>Handler</h1> <ul> <li><a href="#" onclick="ajaxpage('directory', 'content'); return false;">Directory</a></li> </ul> <?php if(isset($_SESSION['admin'])){ if($_SESSION['admin'] <= 2){ }} ?> <h1>Booking</h1> <ul> <li><a href="#" onclick="ajaxpage('champions', 'content'); return false;">Champions</a></li> <li><a href="#" onclick="ajaxpage('booker', 'content'); return false;">Booker</a></li> <li><a href="#" onclick="ajaxpage('compiler', 'content'); return false;">Compiler</a></li> <li><a href="#" onclick="ajaxpage('archives', 'content'); return false;">Archives</a></li> </ul> <?php if(isset($_SESSION['admin'])){ if($_SESSION['admin'] <= 1){ }} ?> <h1>Fed Admin</h1> <ul> <li><a href="#" onclick="ajaxpage('handlers', 'content'); return false;">Handlers</a></li> <li><a href="#" onclick="ajaxpage('characters', 'content'); return false;">Characters</a></li> <li><a href="#" onclick="ajaxpage('applications', 'content'); return false;">Applications</a></li> <li><a href="#" onclick="ajaxpage('eventnames', 'content'); return false;">Event Names</a></li> <li><a href="#" onclick="ajaxpage('titlenames', 'content'); return false;">Title Names</a></li> <li><a href="#" onclick="ajaxpage('matchtypes', 'content'); return false;">Match Types</a></li> <li><a href="#" onclick="ajaxpage('divisions', 'content'); return false;">Divisions</a></li> <li><a href="#" onclick="ajaxpage('countries', 'content'); return false;">Arenas</a></li> </ul> <?php if(isset($_SESSION['admin'])){ if($_SESSION['admin'] <= 0){ }} ?> <h1>Site Admin</h1> <ul> <li><a href="#" onclick="ajaxpage('templates', 'content'); return false;">Templates</a></li> <li><a href="#" onclick="ajaxpage('content', 'content'); return false;">Content</a></li> <li><a href="#" onclick="ajaxpage('biosconfig', 'content'); return false;">Bio Configuration</a></li> <li><a href="#" onclick="ajaxpage('newscat', 'content'); return false;">News Categories</a></li> <li><a href="#" onclick="ajaxpage('menus', 'content'); return false;">Menus</a></li> </ul> </div> <div id=content> </div> <div id="footer">Backstage 1 © 2009 </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/ Share on other sites More sharing options...
revraz Posted December 23, 2008 Share Posted December 23, 2008 You need to put your HTML inside your IF brackets. Right now it's outside so it just displays everything. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722654 Share on other sites More sharing options...
Jabop Posted December 23, 2008 Share Posted December 23, 2008 I would make a permissions table or even serialize an array of available permissions in a column the users table, to make it easier. your concept is very similar but they way you're checking (less than, less than or equal to, etc) doesn't seem to be the best way to do it. what's wrong with what you have, though? edit: revraz beat me to it Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722659 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 if(isset($_SESSION['admin'])){ if($_SESSION['admin'] }} This doesn't do anything except check if $_SESSION['admin'] You should either do what revraz said: You need to put your HTML inside your IF brackets. Right now it's outside so it just displays everything. Or make a case/switch statement. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722661 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722665 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 For example shouldn't these if statements encapsulate the HTML you want to show? (BWT I rewrote your if statement) if(isset($_SESSION['admin']) && $_SESSION['admin'] Fed Admin </pre> <ul> Handlers Characters Applications Event Names Title Names Match Types Divisions Arenas </ul Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722672 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 Thank you Maq however can you explain what the if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 1) { ?> means? Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722676 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 If both conditions are true. If $_SESSION['admin'] is set and is It's the same as what you had but 1 IF rather than 2. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722682 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 Okay I understand that some however my DB table in my users table has a field called admin and is a bool type and will either be 1 to mean they are an admin and 2 to mean they aren't an admin. Does your code there still work with that DB table field? Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722690 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 Try it! I told you it is the same as yours except it's compressed into 1 line rather than 2. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722691 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 Well obviously I can't see the functions (options) on the left which means that part works but I mean I don't think my login is right. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722695 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 I mean I don't think my login is right. And what would lead you to believe that? Please shore so we can help Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722704 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 I have my login script above in my first post. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722710 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 I assume Login Script is "backstage.php" And Control Panel is: ? You should submit the form to itself like: </pre> <form method="POST" action="<?php%20echo%20%24_SERVER%5B'PHP_SELF'%5D;%20?>">< Does anything happen? Did you echo anything out to make sure they're the correct values? We kind of need some more information... Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722719 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 Well I do have a screw up. The Login script is the top coding which is login.php and the second coding part is the Control Panel which is backstage.php. What I want is everything in the login.php script to be added to the top of backstage script so that it'll still work. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722723 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 Well I do have a screw up. The Login script is the top coding which is login.php and the second coding part is the Control Panel which is backstage.php. What I want is everything in the login.php script to be added to the top of backstage script so that it'll still work. ok... so go try it out and come back with questions. This is easily possible with a little effort. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722727 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 Okay so I just C&P the content in login.php into the top portion of backstage.php to create the following new coding for backstage.php. <?php //if the login form is submitted if(isset($_POST['login'])) { // makes sure they filled it in if(!$_POST['username'] || !$_POST['pass']) { die('You did not fill in a required field.'); } $username = mysql_real_escape_string($_POST['username']); $pass = mysql_real_escape_string($_POST['pass']); $check = mysql_query("SELECT * FROM users WHERE username = '".$username."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.'); } while($info = mysql_fetch_array( $check )) { $pass = md5(stripslashes($_POST['pass'])); $info['password'] = stripslashes($info['password']); //$_POST['pass'] = md5($_POST['pass']); THIS IS DONE IN THE ABOVE STATEMENT //gives error if the password is wrong if ($pass != $info['password']) { die('Incorrect password, please try again.'); } else // if login is ok then we add a cookie and send them to the correct page { $username = stripslashes($username); session_start(); $_SESSION['username'] = $username; $_SESSION['loggedin'] = time(); // Finds out the user type $query = "SELECT `admin` FROM `users` WHERE `username` = '" . $username . "'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $admin = $row['admin']; $_SESSION['admin'] = $admin; } } } else { // if they have not submitted the form ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Language" content="en-us"> <meta name="language" content="en-us"> <title>Backstage V1 Administration Console</title> <link rel=stylesheet href=backstage.css type=css media=screen> <link rel=stylesheet href=backstage_print.css type=css media=print> </head> <body> <div id=login> <form method="POST" action="http://kansasoutlawwrestling.com/other/backstage.php"> <h1>KOW Backstage</h1> <p><label>Username:<br><input type=text name=uname id=log tabindex=1></label></p> <p><label>Password:<br><input type=password name=pword id=pwd tabindex=2></label></p> <p style="text-align: center;"><input type=submit class=button name=submit id=submit value="Login »" tabindex=4></p> </form> </div> </body> </html> <?php } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Language" content="en-us"> <meta name="language" content="en-us"> <title>Backstage V1 Administration Console</title> <link rel="stylesheet" href="backstage.css" type="text/css" media="screen"> <link rel="stylesheet" href="backstage_print.css" type="text/css" media="print"> <script src="prototype.js" type="text/javascript"></script> <script src="scriptaculous.js" type="text/javascript"></script> <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var page = document.cookie.match(/page=[\w][\w\-\.]+;/); if(page != null) { ajaxpage("page", "content"); } else { ajaxpage("home", "content"); } </script> </head> <body> <div id=container> <div class=header> <table cellpadding="0" cellspacing="0" border="0" width="95%"> <tr> <td width=110 align=center></td> <td></td> <td width=40 valign=bottom align=right> <a href="#" onclick="ajaxpage('home', 'content'); return false;">Home</a> | <a href="#" onclick="ajaxpage('logout', 'content'); return false;">Logout</a> | <a target="_blank" href="http://kansasoutlawwrestling.com/phpBB3">Forums</a></td> </tr> </table> </div> <div id=container2> <div id=nav> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 1) { ?> <h1>Character</h1> <ul> <li><a href="#" onclick="ajaxpage('bio', 'content'); return false;">Bio</a></li> <li><a href="#" onclick="ajaxpage('allies', 'content'); return false;">Allies</a></li> <li><a href="#" onclick="ajaxpage('rivals', 'content'); return false;">Rivals</a></li> <li><a href="#" onclick="ajaxpage('quotes', 'content'); return false;">Quotes</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 4) { ?> <h1>Submit</h1> <ul> <li><a href="#" onclick="ajaxpage('roleplay', 'content'); return false;">Roleplay</a></li> <li><a href="#" onclick="ajaxpage('news', 'content'); return false;">News</a></li> <li><a href="#" onclick="ajaxpage('match', 'content'); return false;">Match</a></li> <li><a href="#" onclick="ajaxpage('seg', 'content'); return false;">Seg</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 3) { ?> <h1>Handler</h1> <ul> <li><a href="#" onclick="ajaxpage('directory', 'content'); return false;">Directory</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 2) { ?> <h1>Booking</h1> <ul> <li><a href="#" onclick="ajaxpage('champions', 'content'); return false;">Champions</a></li> <li><a href="#" onclick="ajaxpage('booker', 'content'); return false;">Booker</a></li> <li><a href="#" onclick="ajaxpage('compiler', 'content'); return false;">Compiler</a></li> <li><a href="#" onclick="ajaxpage('archives', 'content'); return false;">Archives</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 1) { ?> <h1>Fed Admin</h1> <ul> <li><a href="#" onclick="ajaxpage('handlers', 'content'); return false;">Handlers</a></li> <li><a href="#" onclick="ajaxpage('characters', 'content'); return false;">Characters</a></li> <li><a href="#" onclick="ajaxpage('applications', 'content'); return false;">Applications</a></li> <li><a href="#" onclick="ajaxpage('eventnames', 'content'); return false;">Event Names</a></li> <li><a href="#" onclick="ajaxpage('titlenames', 'content'); return false;">Title Names</a></li> <li><a href="#" onclick="ajaxpage('matchtypes', 'content'); return false;">Match Types</a></li> <li><a href="#" onclick="ajaxpage('divisions', 'content'); return false;">Divisions</a></li> <li><a href="#" onclick="ajaxpage('countries', 'content'); return false;">Arenas</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 0) { ?> <h1>Site Admin</h1> <ul> <li><a href="#" onclick="ajaxpage('templates', 'content'); return false;">Templates</a></li> <li><a href="#" onclick="ajaxpage('content', 'content'); return false;">Content</a></li> <li><a href="#" onclick="ajaxpage('biosconfig', 'content'); return false;">Bio Configuration</a></li> <li><a href="#" onclick="ajaxpage('newscat', 'content'); return false;">News Categories</a></li> <li><a href="#" onclick="ajaxpage('menus', 'content'); return false;">Menus</a></li> </ul> <?php } ?> </div> <div id=content> </div> <div id="footer">Backstage 1 © 2009 </div> </div> </div> </body> </html> Located at: http://kansasoutlawwrestling.com/other/backstage.php Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722733 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 I can't test anything right now so bear with me. I bet you have a lot of errors. I fixed up some of your script but I think it would be better to do sort of a trial and error for this. Try this and give me all of your errors... //if the login form is submitted if(isset($_POST['login'])) { // makes sure they filled it in if(!$_POST['username'] || !$_POST['pass']) { die('You did not fill in a required field.'); } $username = mysql_real_escape_string($_POST['username']); $pass = mysql_real_escape_string($_POST['pass']); $check = mysql_query("SELECT * FROM users WHERE username = '".$username."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.'); } while($info = mysql_fetch_array( $check )) { $pass = md5(stripslashes($_POST['pass'])); $info['password'] = stripslashes($info['password']); //$_POST['pass'] = md5($_POST['pass']); THIS IS DONE IN THE ABOVE STATEMENT //gives error if the password is wrong if ($pass != $info['password']) { die('Incorrect password, please try again.'); } else // if login is ok then we add a cookie and send them to the correct page { $username = stripslashes($username); session_start(); $_SESSION['username'] = $username; $_SESSION['loggedin'] = time(); // Finds out the user type $query = "SELECT `admin` FROM `users` WHERE `username` = '" . $username . "'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $admin = $row['admin']; $_SESSION['admin'] = $admin; } } } else { // if they have not submitted the form ?> Backstage V1 Administration Console <br /> var page = document.cookie.match(/page=[\w][\w\-\.]+;/);<br /> if(page != null) {<br /> ajaxpage("page", "content");<br /> } else {<br /> ajaxpage("home", "content");<br /> }<br /> KOW Backstage Username: Password: } ?> Home | Logout | Forums Character Bio Allies Rivals Quotes Submit Roleplay News Match Seg Handler Directory Booking Champions Booker Compiler Archives Fed Admin Handlers Characters Applications Event Names Title Names Match Types Divisions Arenas Site Admin Templates Content Bio Configuration News Categories Menus Backstage 1 © 2009 Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722740 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 No errors. Nothing happens. I made a test page for just working on it until I get a final copy is made. I'm running off the http://kansasoutlawwrestling.com/other/backstage2.php page now. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722749 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 Add these lines at the top of your script: ini_set ("display_errors", "1"); error_reporting(E_ALL); Have you tried echoing anything out to make sure it's being submitted to the page? Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722760 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 No but its a little odd that when you load http://kansasoutlawwrestling.com/other/backstage2.php it show the login form and the CP at the same time. Why is that? Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722763 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 Do this: Home | Logout | Forums Character Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722765 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 <?php //if the login form is submitted if(isset($_POST['login'])) { // makes sure they filled it in if(!$_POST['username'] || !$_POST['pass']) { die('You did not fill in a required field.'); } $username = mysql_real_escape_string($_POST['username']); $pass = mysql_real_escape_string($_POST['pass']); $check = mysql_query("SELECT * FROM users WHERE username = '".$username."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.'); } while($info = mysql_fetch_array( $check )) { $pass = md5(stripslashes($_POST['pass'])); $info['password'] = stripslashes($info['password']); //$_POST['pass'] = md5($_POST['pass']); THIS IS DONE IN THE ABOVE STATEMENT //gives error if the password is wrong if ($pass != $info['password']) { die('Incorrect password, please try again.'); } else // if login is ok then we add a cookie and send them to the correct page { $username = stripslashes($username); session_start(); $_SESSION['username'] = $username; $_SESSION['loggedin'] = time(); // Finds out the user type $query = "SELECT `admin` FROM `users` WHERE `username` = '" . $username . "'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $admin = $row['admin']; $_SESSION['admin'] = $admin; } } } else { // if they have not submitted the form ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Language" content="en-us"> <meta name="language" content="en-us"> <title>Backstage V1 Administration Console</title> <link rel="stylesheet" href="backstage.css" type="text/css" media="screen"> <link rel="stylesheet" href="backstage_print.css" type="text/css" media="print"> <script src="prototype.js" type="text/javascript"></script> <script src="scriptaculous.js" type="text/javascript"></script> <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var page = document.cookie.match(/page=[\w][\w\-\.]+;/); if(page != null) { ajaxpage("page", "content"); } else { ajaxpage("home", "content"); } </script> <link rel=stylesheet href=backstage.css type=css media=screen> <link rel=stylesheet href=backstage_print.css type=css media=print> </head> <body> <div id=login> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <h1>KOW Backstage</h1> <p><label>Username:<br><input type=text name=uname id=log tabindex=1></label></p> <p><label>Password:<br><input type=password name=pword id=pwd tabindex=2></label></p> <p style="text-align: center;"><input type=submit class=button name=submit id=submit value="Login »" tabindex=4></p> </form> </div> <?php } ?> <?php if(isset($_SESSION['admin']) { ?> <div id=container> <div class=header> <table cellpadding="0" cellspacing="0" border="0" width="95%"> <tr> <td width=110 align=center></td> <td></td> <td width=40 valign=bottom align=right> <a href="#" onclick="ajaxpage('home', 'content'); return false;">Home</a> | <a href="#" onclick="ajaxpage('logout', 'content'); return false;">Logout</a> | <a target="_blank" href="http://kansasoutlawwrestling.com/phpBB3">Forums</a></td> </tr> </table> </div> <div id=container2> <div id=nav> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 1) { ?> <h1>Character</h1> <ul> <li><a href="#" onclick="ajaxpage('bio', 'content'); return false;">Bio</a></li> <li><a href="#" onclick="ajaxpage('allies', 'content'); return false;">Allies</a></li> <li><a href="#" onclick="ajaxpage('rivals', 'content'); return false;">Rivals</a></li> <li><a href="#" onclick="ajaxpage('quotes', 'content'); return false;">Quotes</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 4) { ?> <h1>Submit</h1> <ul> <li><a href="#" onclick="ajaxpage('roleplay', 'content'); return false;">Roleplay</a></li> <li><a href="#" onclick="ajaxpage('news', 'content'); return false;">News</a></li> <li><a href="#" onclick="ajaxpage('match', 'content'); return false;">Match</a></li> <li><a href="#" onclick="ajaxpage('seg', 'content'); return false;">Seg</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 3) { ?> <h1>Handler</h1> <ul> <li><a href="#" onclick="ajaxpage('directory', 'content'); return false;">Directory</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 2) { ?> <h1>Booking</h1> <ul> <li><a href="#" onclick="ajaxpage('champions', 'content'); return false;">Champions</a></li> <li><a href="#" onclick="ajaxpage('booker', 'content'); return false;">Booker</a></li> <li><a href="#" onclick="ajaxpage('compiler', 'content'); return false;">Compiler</a></li> <li><a href="#" onclick="ajaxpage('archives', 'content'); return false;">Archives</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 1) { ?> <h1>Fed Admin</h1> <ul> <li><a href="#" onclick="ajaxpage('handlers', 'content'); return false;">Handlers</a></li> <li><a href="#" onclick="ajaxpage('characters', 'content'); return false;">Characters</a></li> <li><a href="#" onclick="ajaxpage('applications', 'content'); return false;">Applications</a></li> <li><a href="#" onclick="ajaxpage('eventnames', 'content'); return false;">Event Names</a></li> <li><a href="#" onclick="ajaxpage('titlenames', 'content'); return false;">Title Names</a></li> <li><a href="#" onclick="ajaxpage('matchtypes', 'content'); return false;">Match Types</a></li> <li><a href="#" onclick="ajaxpage('divisions', 'content'); return false;">Divisions</a></li> <li><a href="#" onclick="ajaxpage('countries', 'content'); return false;">Arenas</a></li> </ul> <?php } ?> <?php if(isset($_SESSION['admin']) && $_SESSION['admin'] <= 0) { ?> <h1>Site Admin</h1> <ul> <li><a href="#" onclick="ajaxpage('templates', 'content'); return false;">Templates</a></li> <li><a href="#" onclick="ajaxpage('content', 'content'); return false;">Content</a></li> <li><a href="#" onclick="ajaxpage('biosconfig', 'content'); return false;">Bio Configuration</a></li> <li><a href="#" onclick="ajaxpage('newscat', 'content'); return false;">News Categories</a></li> <li><a href="#" onclick="ajaxpage('menus', 'content'); return false;">Menus</a></li> </ul> <?php } ?> </div> <div id=content> </div> <div id="footer">Backstage 1 © 2009 </div> </div> </div> </body> </html> <?php } else{ ?> Parse error: syntax error, unexpected '{' in /home/content/y/a/n/yankeefaninkc/html/other/backstage2.php on line 92 Double check that I made all the correct changes. Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722774 Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 lol missing a ')' Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722777 Share on other sites More sharing options...
Xtremer360 Posted December 23, 2008 Author Share Posted December 23, 2008 Parse error: syntax error, unexpected $end in /home/content/y/a/n/yankeefaninkc/html/other/backstage2.php on line 176 Quote Link to comment https://forums.phpfreaks.com/topic/138224-limiting-options-to-users/#findComment-722778 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.