我需要三种不同的用户类型:访客、作者和管理员。当用户注册时,他们通过下拉列表选择他们是作者还是管理员。这三种不同的类型具有不同的功能。
目前,无论他们是否登录,都会在他们登录后分配访客。
<?php
include("dbconnect.php");
$con = new dbconnect();
$con->connect();
session_start();
if (isset($_POST['submit']))
{
$sql = "SELECT type FROM Users WHERE username = '".$_POST["username"]."' AND password = ('". sha1($_POST["password"]) ."')";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1) {
$type_num=0;
while ($info = mysql_fetch_array($result)) {
$type =$info['type'];
}
if($type == "admin")
{
$_SESSION['type']=2;
$_SESSION['username']= $_POST["username"];
header("Location: viewPosts.php");
}
if($type == "author")
{
$_SESSION['type']=1;
$_SESSION['username']= $_POST["username"];
header("Location: viewPosts.php");
}
else
{
$_SESSION['type']= $type_num;
$_SESSION['username']="guest";
header("Location: viewPosts.php");
}
} else {
//redirect back to login form if not authorized
header("Location: loginfailed.html");
exit;
}
}
?>
我如何得到它,以便正确分配这些变量?谢谢!