Jump to content

[SOLVED] login scripts


182x

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/59133-solved-login-scripts/
Share on other sites

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!!";
}

Link to comment
https://forums.phpfreaks.com/topic/59133-solved-login-scripts/#findComment-293641
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.