182x Posted July 9, 2007 Share Posted July 9, 2007 Hey guys, I am trying to write a login script which can manage 4 different types of user so for example if one of the admin users logs in they will be taken to the admin section or another user will be taken to their section with their proper privileges. I have never done anything like this before and was just wondering what would be the best way to do this, or are there any scripts that can help with this? Thanks for any advice. Quote Link to comment Share on other sites More sharing options...
marcus Posted July 9, 2007 Share Posted July 9, 2007 You could just select the field from the databasing depending on the user. Then use switch to call where you want them to go. //saying username and password are defined as variables $sql = "SELECT * FROM `users` WHERE `username` ='$username'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0){ $sql2 = "SELECT * FROM `users` WHERE `username` ='$username' AND `password` ='$password'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) > 0){ $row = mysql_fetch_assoc($res2); $level = $row[level]; //saying level 1 = user, level 2 = mod, level 3 user admin, level 4 = admin switch($level){ case 1: $direct = "/main.php"; break; case 2: $direct = "/mod/index.php"; break; case 3: $direct = "/ua/index.php"; break; case 4: $direct = "/admin/index.php"; break; default: $direct = "/main.php"; break; } echo "<script language=\"javascript\">\nalert(\"You are now logged in!\")\nalert(\"You are being redirected to $direct\")\nwindow.location.href=\"$direct\"</script>\n"; }else { echo "Username and Password combination is incorrect!\n"; } }else { echo "The username you supplied does not exist!!"; } Quote Link to comment Share on other sites More sharing options...
182x Posted July 9, 2007 Author Share Posted July 9, 2007 That looks like a very clever way of doing it. Thanks for your help Quote Link to comment 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.