0

ゲスト、作成者、および管理者という 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;
    }
}
?>

これらの変数を正しく割り当てるにはどうすればよいですか?? ありがとう!

4

1 に答える 1

1

問題の原因:if($type == "author")

に変更しelseif ($type == "author")ます。これにより、条件付きチェック スレッドが最後まで適切に続行されるようになります。それ以外の場合は、そこにある最後のステートメントを$type == "admin"常に呼び出します。else

于 2013-07-13T02:18:06.490 に答える