我正在尝试通过不同的UserType
登录php和sql server我尝试在没有UserType
的情况下登录,我可以登录。但我不知道如何根据UserType
进行登录。无论如何,这是我尝试过的:
UserType :
login_action.php (没有用户类型)
<?php
session_start();
require_once 'connection.php';
$EmployeeId = $_POST['EmployeeId'];
$Password = $_POST['Password'];
$tsql = "SELECT * FROM LOGIN WHERE EmployeeId='$EmployeeId' AND Password='$Password'";
$result = sqlsrv_query( $conn, $tsql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
$num = sqlsrv_num_rows($result);
if($num==1){
header('Location: user.php');
$_SESSION['valid_user'] = true;
$_SESSION['EmployeeId'] = $EmployeeId;
die();}
else
header('Location: login.php');
die();
?>
login_action.php (使用UserType)
<?php
session_start();
require_once 'connection.php';
$EmployeeId = $_POST['EmployeeId'];
$Password = $_POST['Password'];
$UserType = $_POST['UserType'];
$tsql = "SELECT * FROM LOGIN WHERE EmployeeId='$EmployeeId' AND Password='$Password' AND UserType='$UserType'";
$result = sqlsrv_query( $conn, $tsql,$params , array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
$num = sqlsrv_num_rows($result);
if($num==1){
$_SESSION['EmployeeId']=$EmployeeId;
$_SESSION['UserType']=$UserType;
if($UserType=="USER")
{
header("Location:user.php");
}
else if ($UserType=="SUPERIOR")
{
header("Location:superior.php");
}
else if ($UserType=="ADMIN")
{
header("Location:admin.php");
}
else
die("Not a valid User Type");
}
else
header('Location: login.php');
?>
答案 0 :(得分:1)
没关系,我已经解决了。我只是忘了写这一行:
$_SESSION['valid_user'] = true;
正如Fred -ii-建议的那样,我已经添加了exit();在每个标题之后