2012-07-29 51 views
1

我在代碼中包含一個標題(),但它不重定向。我知道在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"); ?> 
+0

你確定'$ _SESSION ['owner']'被設置了嗎?嘗試將你的'if'語句改爲'if(true){'來測試它;如果重定向 - 問題是會話變量未設置(或爲空)。 – newfurniturey 2012-07-29 01:35:24

+1

請定義「不起作用」。和位置應該是一個完整的網址,而不僅僅是一個文件名 – 2012-07-29 01:55:01

+0

如果設置了'$ _SESSION ['owner']''也許你在開始時用BOM保存你的文件?檢查你的編輯器的文檔,並確保你沒有。 – Galen 2012-07-29 02:07:59

回答

0

你有PHP的關閉和開啓塊之間的換行符:

?> 
<?php 

沒有必要爲這些標籤。刪除它們兩個。

相關問題