1

我在我的代码中包含了一个 header() 但它不会重定向。我知道在发送 header() 之前不应该有任何空白,但它仍然不起作用。有人可以帮忙吗?提前致谢。

<?php 
    session_start();
    if(isset($_SESSION["owner"])){
        header("Location:index.php");
        exit();
    }
?>
<?php
require_once("includes/connection.php");
if(isset($_POST["username"]) && isset($_POST["password"])){
$owner = $_POST["username"];
$password = $_POST["password"];
$query = "SELECT id FROM users WHERE username = '$owner' AND password ='$password' LIMIT 1";
 $sql = mysql_query($query,$connection);
 $existCount = mysql_num_rows($sql);
        if($existCount == 1){   
        while($row = mysql_fetch_array($sql)){
        $id = $row["id"];
        }
        $_SESSION["id"] =$id;
        $_SESSION["owner"] = $owner; 
        $_SESSION["password"] =$password;
        header("Location:list.php");
        exit();
        }else{
        header("Location:login.php");
        exit();
        }
}
require_once("includes/header.php");?>
<div class="cBoth"></div>
<div id="sep"></div>

<div class="Calign">
<div id="formcontent">

<div class="flotr">
 <h2>Learn More</h2> 
 <p class="widthis">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p>
</div><!-- end of flotr div text --->

<div class="flotr">
   <fieldset class="spacing">
   <form method="post" action="admin/formProc/formproc.php">
     <h2>New to MaalHouse?</h2>
     <p class="widthis">A Maalhouse account is required to continue.</p> 
     <p class="formsp">Name</p>
     <p><label><input type="text" name="username" height="15px"/><label></p>
     <p class="formsp">Email</p>
     <p><label><input type="text" name="email"/><label></p>
     <p class="formsp">Re-email</p>
     <p><label><input type="text" name="reemail"/><label></p>
     <p class="formsp">Password</p> 
     <p><label><input type="password" name="password"/><label></p>
     <p class="formsp">Re-password</p>
     <p><label><input type="password" name="repassword"/><label></p>
     <p class="formsp"><label><input type="submit" name="newuser" value="SING ME UP"/><label></p>
   </form>
  </fieldset>
</div><!-- end of flotr div sign up--->




<div class="flotl">
   <fieldset class="spacing">
   <form method="post" action="login.php">
   <h2>New to MaalHouse?</h2>
   <p class="widthis">A Maalhouse account is required to continue.</p> 
   <p class="formsp">Username</p>
   <p><input type="text" name="username"/></p>
   <p class="formsp">Password</p>
   <p><input type="password" name="password"/></p>
   <p></p>
   <p class="formsp"><label><input type="submit" name="login" value="Login"/><label></p>   
   </form>
   </fieldset>
</div><!-- end of flotl div login--->


 </div>
</div>


<div class="cBoth"><!-- clear Both--></div> 
<?php require_once("includes/footer.php"); ?> 
4

1 回答 1

0

在 PHP 的结束块和开始块之间有一个换行符:

?>
<?php

不需要这些标签。删除它们。

于 2012-10-22T12:27:27.287 回答