header()打印到控制台而不是重定向

时间:2014-08-21 05:04:40

标签: php

我试图重定向到另一个页面但没有发生任何事情。页面永远不会更改,并且我尝试重定向到的页面的html正在控制台中显示。这有什么理由吗?

代码:

if($bExisitngUser){
/*
 * Set of variables for existing user
 */
 $sUserName = $_POST['sUserName'];
 $sPassword = $_POST['sPassword'];
 $bRememberMe = $_POST['bRememberMe'];

$queryResults = makeLoginRequest('user', $sUserName, $sPassword);
  if($queryResults !== null){
      header('Location: http://www.google.com');
      exit();
  } else{
      header('Location: ../../../ProfilePortal/php/profile.php');
      exit();
  }
}

function conn($sQuery){
    $sMessage = '';
    $db = new mysqli('localhost','root','','myvyn') or die('unable to connect!');
    if($db->connect_errno){
        $message = $db->connect_error;
    } else{
        if($db->query($sQuery)){
            $stmt = $db->prepare($sQuery);
            $stmt->execute();
            $result = $stmt->get_result();
            for($aResult = array(); $row = $result->fetch_assoc(); $aResult[] = $row);
            //print_r($aResult);
            return $row;
        } else{
            $sMessage = $db->error;
            return $sMessage;
        }
    }
}

function makeLoginRequest($table, $id, $pwd){
    $sQuery = "SELECT * FROM `" . $table . "` WHERE `email` = '" . $id . "' AND `password` = '" . $pwd . "'";
    $result = conn($sQuery);
    if(!isset($result)||!defined("$result")||empty($result)||is_null($result)){
        return null;
    } else{
        return $result;
    }
}

在假设编码正确遵循的情况下工作。上面的第一个if语句位于与其余部分不同的php文件中,并且这些代码都不直接在index.php文件中。我也没有回复或打印任何这些文件。

这实际上是控制台中的内容:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
   'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>

<html xmlns='http://www.w3.org/1999/xhtml' lang='en_US' xml:lang='en_US'>
 <head>
  <title>MyVyn</title>
  <script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?sensor=false&library=places'></script>
  <script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
  <script src='//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js'></script>
  <link rel='stylesheet' href='//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' />
  <link rel='stylesheet' href='../css/profile/banner.css' type='text/css'/>
  <link rel='stylesheet' href='../css/profile/profile.css' type='text/css'/>
 </head>
 <body>
    <div id='banner'>   <div id="searchBarWidget">
        <form method="post">
            <input id="inputSearch" name="Query" type="text" placeholder="Search places, users, and area codes"/>
            <input id="submitSearch" name="Search" type="submit"/>
    </form>
    </div>
    <div id="homeButtonContainer">
        <a id="homeButton" >Home</a>
    </div>
    <div id="profileButtonContainer">
        <a id="profileButton" >Profile</a>
    </div>
    <div id="settingsContainer">Settings
        <div id="settingsMenu">
            <ul>
                <li>settings</li>
                <li>report problem</li>
                <li>
                    <div class="divider"></div>
                </li>
                <li>help</li>
                <li>logout</li>
            </ul>
        </div>
    </div>
</div>
<div id="content">
    <div id="leftContainer">
        <div id="block1" class="block">
            <label id="fullName"></label>
            <div id="placeHolder"></div>
            <!---<img src="http://placehold.it/373x235"></img>--->
        </div>
        <div id="block2" class="block">
            <div id="fullGroupingContainerStyle1">
                <div id="uaGroup" class="groupBoxView">
                    <div id="AUContainer" class="Container">
                        <label class="labelStyle1"># of Admired Users</label>
                    </div>
                </div>
                <div id="avGroup" class="groupBoxView">
                    <div id="AVContainer" class="Container">
                        <label class="labelStyle1"># of Admired Venues</label>
                    </div>
                </div>
                <div id="aGroup" class="groupBoxView">
                    <div id="AContainer" class="Container">
                        <label class="labelStyle1"># of Admirers</label>
                    </div>
                </div>
                <div id="RAgroup">

                </div>  
            </div>
        </div>
        <div id="block3" class="block">
            <div id="questionContainer">
                <div class="question">
                    <label id=""> question 1: </label>
                </div>
                <div class="question">
                    <label id=""> question 2: </label>
                </div>
                <div class="question">
                    <label id=""> question 3: </label>
                </div>
                <div class="question">
                    <label id=""> question 4: </label>
                </div>
                <div class="question">
                    <label id=""> question 5: </label>
                </div>
            </div>
            <div id="answerContainer">
                <div class="answer">
                    <label id="answerOne"> answer 1 </label>
                </div>
                <div class="answer">
                    <label id="answerTwo"> answer 2 </label>
                </div>
                <div class="answer">
                    <label id="answerThree"> answer 3 </label>
                </div>
                <div class="answer">
                    <label id="answerFour"> answer 4 </label>
                </div>
                <div class="answer">
                    <label id="answerFive"> answer 5 </label>
                </div>
            </div>
        </div>
    </div>
    <div id="rightContainer">
        <div id="block4" class="block">
            <div id="status">
                <textarea id="writeNote" col="100" rows="2"></textarea>
                <br>
                <input id="submitNote" type="submit" value="Post"></input>
                <span id="noteCharCount" class="noteCharCount">34</span>
                <span id="noteCharCountLabel" class="noteCharCount">Available char:&nbsp;</span>
            </div>
        </div>
        <div id="block5" class="block">
            <div id="feed"></div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

请在脚本启动时尝试使用 ob_clean()函数 此函数丢弃输出缓冲区的内容。