php登录不会在服务器上重定向

php登录不会在服务器上重定向,php,authentication,redirect,Php,Authentication,Redirect,我在PHP中有一个问题。我有我的登录网页。当我在写下电子邮件和密码并点击login后尝试登录localhost时,它会将我重定向到仪表板。但是当我把我的页面上传到主机上,并且我正在尝试在线上传时,它一开始不会重定向我,我必须刷新或再次登录才能重定向我。我怎样才能修好它?谢谢 以下是我的PHP代码: <?php session_start(); if (isset($_SESSION['user_name']) && !empty($_SESSION['user_name

我在PHP中有一个问题。我有我的登录网页。当我在写下电子邮件和密码并点击login后尝试登录localhost时,它会将我重定向到仪表板。但是当我把我的页面上传到主机上,并且我正在尝试在线上传时,它一开始不会重定向我,我必须刷新或再次登录才能重定向我。我怎样才能修好它?谢谢 以下是我的PHP代码:

<?php
session_start();


if (isset($_SESSION['user_name']) && !empty($_SESSION['user_name'])){
    header('Location: dashboard/index.php');
}

?>

 <?php



            if (isset($_POST['login'])){
                $user_email = $_POST['user_email'];
                $user_password = $_POST['user_password'];



                try{
                    include 'dashboard/includes/db.php';


                    $query = "SELECT * FROM users WHERE user_email = :user_email AND user_password = AES_ENCRYPT(:password, :key)";


                    $send_info = $connection->prepare($query);

                    $send_info->bindParam(':user_email', $user_email);
                    $send_info->bindParam(':password', $user_password);
                    $send_info->bindParam(':key', $key);

                    $send_info->execute();


                    $send_info->setFetchMode(PDO::FETCH_OBJ);
                    $result = $send_info->fetchAll();

                    if(count($result) == 0){
                        $message = "<h6 class='text-danger mt-2'>Chybný email alebo heslo</h6>";
                    }
                    else{
                    
                        foreach ($result as $item){
                            $_SESSION['user_id'] = $item->user_id;
                            $_SESSION['user_email'] = $item->user_email;
                            $_SESSION['user_name'] = $item->user_name;
                            $_SESSION['user_lastname'] = $item->user_lastname;
                            $_SESSION['user_role'] = $item->user_role;
                            $_SESSION['user_function'] = $item->user_function;
                            $_SESSION['user_image'] = $item->user_image;

                            header('Location: dashboard/index.php');
                            exit;
                        }
                    
                    }

                }
                catch (Exception $e){
                    echo $e;
                }

            }
            ?>


我不喜欢?>(空白)是的,空白肯定会导致某些服务器的观察结果。谢谢!!这真的很有帮助。