URL重定向问题不会在服务器上重定向

时间:2014-08-27 16:23:21

标签: php redirect

我功能齐全的网站在我的localhost 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.";

        }


    }

重定向页面的功能如下:

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

我能做的一切,但它只是不起作用显示空白页...你能帮我摆脱这个烂摊子......你有什么想法吗?

此致

3 个答案:

答案 0 :(得分:1)

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

您的HTML:

<!DOCTYPE html>
<html lang="en">
<head>
在调用redirectTo函数之前输出

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

答案 1 :(得分:1)

可能只能使用$url ..请勿设置$url=null

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

让我知道它是否有效..

答案 2 :(得分:1)

在页面的最开头使用<?php ob_start(); ?>,并在页面的最后使用<?php ob_end_flush(); ?>