gavin1512 Posted January 3, 2008 Share Posted January 3, 2008 Good Day, I am currently working on an internal order system for my Dissertation project and having problem locating some code for a multi level log in system, my system has four levels of log in and each will require a different home page, any help would be much appreciated. Thank You Gavin Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/ Share on other sites More sharing options...
shocker-z Posted January 3, 2008 Share Posted January 3, 2008 try somthing like this if you already have a levels column in your table for user level switch ($row['level']) { case 0: header('level0.php'); break; case 1: header('level1.php'); break; case 2: header('level2.php'); break; } Hope that this is of use to you. Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429287 Share on other sites More sharing options...
gavin1512 Posted January 3, 2008 Author Share Posted January 3, 2008 Thanks Liam, That is what I need, not being to great with PHP and mySQL before I spend ages playing about can I just check something... does this line "switch ($row['level']) {" refer to the row in the database? in my case this is access. In mySQL access is either user, manager, approver or administrator, how do I apply these scenarios in to the case? thank you for your help hope you are having a good day. Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429290 Share on other sites More sharing options...
trq Posted January 3, 2008 Share Posted January 3, 2008 <?php switch ($row['access']) { case 'manager': header('manager.php'); break; case 'approver': header('approver.php'); break; case 'admin': header('admin.php'); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429291 Share on other sites More sharing options...
gavin1512 Posted January 3, 2008 Author Share Posted January 3, 2008 Thank you both for your help I will get to work implementing that now and will probably be back with a few more questions a bit later Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429293 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Don't forget to add your 'user' case, unless that is the default. Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429297 Share on other sites More sharing options...
gavin1512 Posted January 3, 2008 Author Share Posted January 3, 2008 still have an issue due to my inexperience with PHP and not having used it for 2 years, I tired embedding the case statement in my If statement for checking username and password, below is my code: <?php session_start(); require "connect.php"; $username = $_GET['username']; $password = $_GET['password']; $query = "select * from employee where username = '".$username."' and password = '".$password."'"; $result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query"); $row= mysql_fetch_array($result); if ($row != null) { $_SESSION['username'] = $row['username']; switch ($row['access']) { case 'user': header('user home.php'); break; case 'manager': header('manager home.php'); break; case 'approver': header('approver home.php'); break; case 'admin': header('admin home.php'); break; } exit(); } else { $message = "Invalid username or password, please try again"; header("Location: home.php? message=$message"); exit(); } ?> If some one could set me straight on where best to put it I will be very relieved lol Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429304 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 looks fine, what is the error or problem that you have? Need to change case 'admin' to case 'administrator' if that is the actual value in the field. Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429305 Share on other sites More sharing options...
gavin1512 Posted January 3, 2008 Author Share Posted January 3, 2008 in my SQL database the field is stored as admin, originally before the case break statement it would just point at user home.php, but now i have tried all four levels of log in and no page loads and no error message is displayed. The page it tries to load is http://localhost/logincheck.php?username=abowell&password=liverpool&submit=Login and not the actual page relevant to the level of log in. Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429309 Share on other sites More sharing options...
wsantos Posted January 3, 2008 Share Posted January 3, 2008 exit(); Do you really want to exit? Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429320 Share on other sites More sharing options...
gavin1512 Posted January 3, 2008 Author Share Posted January 3, 2008 I have tried commenting out exit(); but still no progress on loading the pages in the case statement. Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429366 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Do you have error showing on? You are probably getting a Header error. Try to use a HTML redirect instead of a header and see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429371 Share on other sites More sharing options...
gavin1512 Posted January 3, 2008 Author Share Posted January 3, 2008 I would like to thank everyone for their help, i altered the header to include header('Location: admin home.php') and it has fixed the problem. CHEERS Quote Link to comment https://forums.phpfreaks.com/topic/84302-solved-multi-level-log-in/#findComment-429379 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.