我有一个登录页面。管理员A用于主分支和其他管理员B,C以及分支B,C和D.管理员A可以登录到所有分支,而管理员B,C和D只能登录到他们自己的分支。但现在我可以做的是所有的管理员只能登录到他们自己的分支。我如何做到这一点,管理员A也可以登录到分支B,C和D?用两种不同的条件登录表格
这是我的代码。在数据库中的登录表
if($_POST['username'] && $_POST['password'] && $_POST['txtbranch']) {
$username = $_POST['username'];
$password = $_POST['password'];
$txtbranch = $_POST['txtbranch'];
$hash_pass = $password;
$query = mysqli_query("select * from sysfile where username='".$username."' and password='".$hash_pass."' and branchid='".$txtbranch."' limit 1");
$count_user = mysqli_num_rows($query);
if($count_user==1)
{
$row = mysqli_fetch_array($query);
$_SESSION['userid'] = $row['userid'];
$_SESSION['username'] = $row['username'];
$_SESSION['pin'] = $row['pin'];
$_SESSION['branchid'] = $_POST['txtbranch'];
header("location:dashboard.php?success=1");
}else{
$error = 'Incorrect Username, Password and Branch.';
}
}
'联系A'是一个用户名?你对SQL注入开放,应该有散列密码。 – chris85
你实际上哈希?改变一个变量名不是哈希.. – chris85
这听起来可能让你灰心。请使用准备好的声明并学习如何在推进之前对您的密码进行哈希处理:http://php.net/manual/en/mysqli.prepare.php,http://php.net/manual/en/pdo.prepared-statements .php和http://php.net/manual/en/function.password-hash.php,http://php.net/manual/en/function.password-verify.php –