Php URL重定向问题未在服务器上重定向

Php URL重定向问题未在服务器上重定向,php,redirect,Php,Redirect,我的网站在本地主机wamp服务器上运行良好,但我在1&1将同一文件上载到服务器,重定向不起作用。代码如下 <?php require_once('../model/class.user.php'); ?> <?php require_once('../model/class.person.php'); ?> <?php require_once('../model/class.session.php'); ?> <?php require_once('.

我的网站在本地主机wamp服务器上运行良好,但我在1&1将同一文件上载到服务器,重定向不起作用。代码如下

<?php require_once('../model/class.user.php'); ?>
<?php require_once('../model/class.person.php'); ?>
<?php require_once('../model/class.session.php'); ?>
<?php require_once('../model/class.loginrecord.php'); ?>
<?php require_once('../controller/general_functions.php'); ?>
<?php require_once('../controller/utility_functions.php'); ?>

<!DOCTYPE html>
<html lang="en">
<head>

    if(isset($_POST['checkUser'])){



        $usrnme = htmlspecialchars($_POST['un']);
        $paswrd = htmlspecialchars($_POST['pwd']);

        if(!empty($usrnme) && !empty($paswrd)){

            //verify user credentials 
            $foundUser = User::verify(array($usrnme, $paswrd));


            if($foundUser){ //if user found in DB
                //$errors[] = "Username : found<br />";

                $UID            = $foundUser->id;
                $userRole       = $foundUser->role;
                $userPersonID   = $foundUser->person_id;//user_person_id has stored the reference to person's table

                $ip =   getenv('HTTP_CLIENT_IP')?:
                        getenv('HTTP_X_FORWARDED_FOR')?:
                        getenv('HTTP_X_FORWARDED')?:
                        getenv('HTTP_FORWARDED_FOR')?:
                        getenv('HTTP_FORWARDED')?:
                        getenv('REMOTE_ADDR')?: "UNKNOWN";

                LoginRecord::save(array(null, $foundUser->id, getCurrentDateTime(), $ip));

                $findPerson     = Person::findByID($userPersonID);//find the user based on the 
                $userFN         = Person::fullName($findPerson);//find the full name of the person

                $session->setValues(md5('loginStatus'), encrypt('true'));
                $session->setValues(md5('userID'), encrypt($UID));
                $session->setValues(md5('userFullName'), encrypt($userFN));

                if($userRole == ROLE_ADCMIN)
                {
                    $session->setValues(md5('role'), encrypt(ROLE_ADCMIN));
                    redirectTO('admin/dashboard.php');
                }
                elseif ($userRole == ROLE_AGENT) 
                {
                    $session->setValues(md5('role'), encrypt(ROLE_AGENT));
                    redirectTO('agent/index.php');
                }
                elseif ($userRole == ROLE_OTHER) 
                {
                    redirectTO('superuser/index.php');
                }

            } else {

                $errors[] = "Sorry Username/Password not valid <br />";

            }//end if($foundUser) 

        } else {

            $errors[] = "Text fields are empty.";

        }


    }
我有我能做的一切,但它只是不工作显示空白页。。。你能帮我摆脱这混乱吗。。。你知道吗


关于

在输出数据后,您似乎正在尝试重定向。在将任何输出发送到浏览器之前,必须先发送标题

您的HTML地址:

<!DOCTYPE html>
<html lang="en">
<head>

正在调用重定向到函数之前输出


此外,您的HTML后缺少一个打开的PHP标记。

可能仅用于
$url
。。不要设置
$url=null

function redirectTO($url){
    if($url != null){
        header("Location:{$url}");
        exit();
    }
}

让我知道它是否有效

在页面的最开始使用
,在页面的最末尾使用

但是为什么相同的代码在我的本地主机上没有任何问题?顺便问一下,我在哪里输出数据?@Sharif更新了答案。您正在用HTML输出数据。您还缺少一个PHP标记?我知道在实际代码中无法正确复制它。PHP在本地和服务器上运行的版本是什么?
function redirectTO($url){
    if($url != null){
        header("Location:{$url}");
        exit();
    }
}