0

我有一个我无法弄清楚的问题,我已经用两个单独的服务器测试了相同的代码,即服务器 A 运行良好,而我需要此页面存在的服务器 B 无法运行。我需要允许用户登录系统并捕获登录详细信息以发表公告。

我有以下代码。

<?php
session_start();
ob_start();
require_once("dugsi/validation.php");
?>

Form


<form method="post" id="loginForm" action="dugsi/login_validation.php">
            <div>
                <label for="username">User name</label>
                <input id="username" name="username" type="text" autocomplete="off"/>
                <span id="userInfo"></span>
            </div>
            <div>
                <label for="password">Password</label>
                <input id="password" name="password" type="password" autocomplete="off"/>
                <span id="passwordInfo"></span>
            </div>
            <div>
                <input id="send" name="send" type="submit" value="Login" />
            </div>
        </form>

验证 php 文件

    <?php
date_default_timezone_set('Europe/London');
session_start();
ob_start();

require_once("dbconnection.php");

login_user();


function login_user()
{
    global $conn;
    $username = $_POST['username'];
    $pass = $_POST['password'];

    $password = hash('sha256', $pass);



    try
    {
        $login_sql =  "SELECT * FROM loginuser WHERE username = :username AND password = :password";
        $result = $conn->prepare($login_sql);
        $result->execute(array(':username'=> $username, ':password'=>$password));

        $_SESSION = $result->fetch(PDO::FETCH_ASSOC);

        $row_count = $result->rowCount();

        if($row_count == 1)
        {



            if ($_SESSION['access_level']  == 1)
            {

            }
            //student 
            else if ($_SESSION['access_level'] == 2)
            {
                $student_sql = "SELECT * FROM loginuser, student_module, module,student 
                                     WHERE loginuser.username=student.username 
                                     AND student.username=student_module.student_username 
                                     AND student_module.`module_id` = module.id 
                                     AND loginuser.username= :username";
                $result_student_sql = $conn->prepare($student_sql);
                $result_student_sql->execute(array(':username'=>$username));

                $_SESSION = $result_student_sql->fetch(PDO::FETCH_ASSOC);

                $module = $_SESSION['module_id'];

                switch ($module)
                {
                    case "ab01":
                        header("Location: http://madarasah.com//dugsi/module/ab01_student.php");
                        break;
                    case "ai01":
                        header("Location: http://madarasah.com//project/module/ai01.php");
                        break;
                    case "fa01":
                        header("Location: http://madarasah.com//project/module/fa01.php");
                        break;
                    case "kh01":
                        header("Location: http://madarasah.com//project/module/kh01.php");
                        break;
                    case "ma01":
                        header("Location: http://madarasah.com//project/module/ma01.php");
                        break;
                    case "ma02":
                        header("Location: http://madarasah.com//project/module/ma02.php");
                        break;

                }


            }
            //teacher
            else if ($_SESSION['access_level'] == 3)
            {
            $teacher_sql = "SELECT * FROM loginuser, teacher_module, module,teacher 
                                     WHERE loginuser.username=teacher.username 
                                     AND teacher.username=teacher_module.teacher_username 
                                     AND teacher_module.`module_id` = module.id 
                                     AND loginuser.username= :username";

                $result_teacher_sql = $conn->prepare($teacher_sql);
                $result_teacher_sql->execute(array(':username'=>$username));

                $_SESSION = $result_teacher_sql->fetch(PDO::FETCH_ASSOC);

                $module = $_SESSION['module_id'];


                switch ($module)
                {
                    case "ab01":
                        header("Location: http://madarasah.com/dugsi/module/ab01.php");
                        break;
                    case "ai01":
                        header("Location: http://madarasah.com/dugsi/module/ai01.php");
                        break;
                    case "fa01":
                        header("Location: http://madarasah.com/dugsi/module/fa01.php");
                        break;
                    case "kh01":
                        header("Location: http://madarasah.com/dugsi/module/kh01.php");
                        break;
                    case "ma01":
                        header("Location: http://madarasah.com/dugsi/module/ma01.php");
                        break;
                    case "ma02":
                        header("Location: http://madarasah.com/dugsi/module/ma02.php");
                        break;

                }

            }

            else if ($_SESSION['access_level'] == 4) 
            {
                $admin_sql = "SELECT * FROM loginuser, admin 
                                     WHERE loginuser.username=admin.username 
                                     AND loginuser.username= :username";
                $result_admin_sql = $conn->prepare($admin_sql);
                $result_admin_sql->execute(array(':username'=>$username));

                $_SESSION = $result_admin_sql->fetch(PDO::FETCH_ASSOC);

                header("Location:http://madarasah.com/dugsi/admin/admin.php");

                exit();

            }
        }
        else
        {
            echo "wrond login details";
        }

    $conn = null;

    }
    catch(PDOException $exception)
    {
         printf("Failed to fetch the database. Error: %s",  $exception->getMessage());
    }

}

ob_flush(); 
?>
4

0 回答 0