ゲスト、作成者、および管理者という 3 つの異なるユーザー タイプが必要です。ユーザーが登録すると、作成者か管理者かをドロップダウン リストで選択します。3 つの異なるタイプには異なる機能があります。
現在、ログインに関係なく、ログイン後にゲストが割り当てられます。
<?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;
}
}
?>
これらの変数を正しく割り当てるにはどうすればよいですか?? ありがとう!