为什么我得到500服务器错误PHP?

时间:2018-03-24 11:43:28

标签: php html redirect

实际上,当用户输入他的电子邮件和密码时,输入enter..it显示服务器错误!

错误500

但是当我刷新页面时它工作得很好......

为什么我在首次登录时遇到服务器错误..

这是我的代码:

的login.php

    if(isset($_POST['btn-login']))
{
    $email = trim($_POST['txtemail']);
    $upass = trim($_POST['txtupass']);


            $stmt = $user_login->runQuery("SELECT * FROM jusers WHERE jemail=:email_id");
            $stmt->execute(array(":email_id"=>$email));
            $userRow=$stmt->fetch(PDO::FETCH_ASSOC);

            if($stmt->rowCount() == 1)
            {   

                    if($userRow['jpass']==md5($upass))
                    {    

                     $_SESSION['user']= array(
                        'juid' =>$userRow['juid'],
                        'username'=>$userRow['jemail'],
                        'password'=>$userRow['jpass'],
                        'role'=>$userRow['role']
                     );

                     $role= $_SESSION['user']['role'];

                      switch ($role) {

                        case 'admin':

                            header("Location : super_admin.php");
                            break;

                        case 'user' :

                             header("Location : admin_user.php");
                             break;
                      }


                    }
                    else
                    {

                        $errMSG =" <div class='alertmsg alert'>
                                    <a class='clostalert'>close</a>
                                    <strong>Warning!</strong> Wrong password </div> ";              
                    }

            }
            else
            {

                $errMSG = " <div class='errormsg alert'>
                            <a class='clostalert'>close</a>
                            <strong>Error!</strong> Wrong credentials!</div> ";            
            }   

用户正确登录后我的admin_user.php

    <?php

 session_start();
 require_once 'class.user.php';
 $admin_user = new USER();

 if(empty($_SESSION['user'])){

   header('location:login.php');

}

if($_SESSION['user']['role']=='admin'){

 header('location:super_admin.php');

}


 if(!$admin_user->is_logged_in())
{
    $admin_user->redirect('login.php');
}

 $sid = $_SESSION['user']['juid'];

   $stmt = $admin_user->runQuery('select jname from jusers where juid = :sid');
   $stmt->bindParam(':sid', $sid);
   $stmt->execute();

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

     extract($row);

     }

?>

这有什么不对......

任何建议都会非常感谢...

2 个答案:

答案 0 :(得分:1)

所以不要在位置添加空格' '。更改您的开关案例如下:

switch ($role) {

                        case 'admin':

                            header("Location:super_admin.php");
                            break;

                        case 'user' :

                             header("Location:admin_user.php");
                             break;
                      }

答案 1 :(得分:1)

:

之前尝试没有空格的Location

header("Location: super_admin.php");header("Location: admin_user.php");