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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.