我制作了一个带有注册/登录系统的网站,我也想制作一个管理面板。我给了我的帐户管理员用户类型 (mysql),但我不知道如何在登录时检查用户类型。这是我检查登录的身份验证代码(echos 有匈牙利语文本不关心):
session_start();
$DATABASE_HOST = 'sql305.epizy.com';
$DATABASE_USER = 'epiz_25331636';
$DATABASE_PASS = 'q1SI3G8B0s';
$DATABASE_NAME = 'epiz_25331636_accounts';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if ( !isset($_POST['username'], $_POST['password']) ) {
exit('Felhasználónév és jelszó is szükséges!');
}
if ($stmt = $con->prepare('SELECT id, password FROM accounts WHERE username = ?')) {
$stmt->bind_param('s', $_POST['username']);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $password);
$stmt->fetch();
if (password_verify($_POST['password'], $password)) {
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['name'] = $_POST['username'];
$_SESSION['id'] = $id;
header('Location: home.php');
} else {
echo "<script type='text/javascript'>alert('Helytelen jelszó');
window.location='index.html';
</script>";
}
} else {
echo "<script type='text/javascript'>alert('Helytelen felhasználónév');
window.location='index.html';
</script>";
}
$stmt->close();
}
?>
炎炎设计