1 回答
TA贡献1805条经验 获得超9个赞
您的代码出错,您的代码无法设置会话,当条件成立时,它会根据您使用的条件将用户重定向到另一个 .php 页面。
试试这段代码。
<?php session_start(); ?>
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$row = mysqli_fetch_assoc($results);
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
//if you want to redirect user as per its type, you can use this condition
if('student' == $row['user_type']) {
header('Location: ogrenciarayuzu.php');
exit();
} elseif ('department' == $row['user_type']) {
header('Location: bolumsekreterligiarayuzu.php');
exit();
} elseif ('institute' == $row['user_type']) {
header('Location: enstituarayuzu.php');
exit();
}
else
{
header('location: index.php');
}
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报