2013-02-20 56 views
0

我不知道爲什麼我的代碼無法重定向。我做了什麼錯誤... 它顯示的警告是 (((警告:無法修改標題信息 - 頭已經發出)))...請有人告訴我需要改變,以成功地重定向...我的代碼::header()無法重定向

<?php 
include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ; 
$email = $_POST['email']; 
$password1 = $_POST['password1']; 
$password2 = $_POST['password2']; 
$firstname = $_POST['firstname']; 
$lastname = $_POST['lastname']; 
if($password1 != $password2) 
{ 
    header('Location: http://localhost/home/'); 
    echo "<script language=javascript> alert(\"RE-ENTERED PASSWORD DOESN'T MATCH   WITH THE ORIGINAL ONE\");</script>"; 
    exit(); 
} 
if($firstname == "" or $firstname == "First Name") 
{ 
    header('Location: http://localhost/home/'); 
    echo "<script language=javascript> alert(\"INVALID FIRST NAME\");</script>"; 
    exit(); 
} 
if($lastname == "" or $lastname == "Last Name") 
{ 
    header('Location: http://localhost/home/'); 
    echo "<script language=javascript> alert(\"INVALID LAST NAME\");</script>"; 
    exit(); 
} 
//INSERTION INTO THE DATABASE STARTS FROM HERE......... 
$email = mysqli_real_escape_string($link,$_POST['email']); 
$password1= mysqli_real_escape_string($link,$_POST['password1']); 
$firstname= mysqli_real_escape_string($link,$_POST['firstname']); 
$lastname= mysqli_real_escape_string($link,$_POST['lastname']); 
$password=md5($password1); 
$sql = "INSERT INTO users SET 
    email = '$email', 
    password = '$password', 
    firstname = '$firstname', 
    lastname = '$lastname'"; 
if (!mysqli_query($link, $sql)) 
{ 
    header('Location: http://localhost/home/'); 
    echo "<script language=javascript> alert(\"THIS E-MAIL ID HAS ALREADY USED BEFORE !!!\");</script>"; 
    exit(); 
} 
else 
{ 
    header('Location: http://localhost/home/'); 
    echo "<script language=javascript> alert(\"REGISTRATION SUCCESSFULLY COMPLETED !!!    \");</script>"; 
    exit(); 
}   
?> 
+1

確保include/db.inc.php中沒有空格。一個'<?php [...]?>'('?>'後面的空格/換行符)會產生這個錯誤。 – tobspr 2013-02-20 12:19:13

+1

重定向到新的URL **或**從當前URL輸出HTML。 *選一個*。 – Quentin 2013-02-20 12:20:17

+0

@ TobSpr..no db.inc.php中沒有空格..必須有其他問題..請幫助 – 2013-02-20 12:26:10

回答

2

檢查任何輸出(回聲),或在db.inc.php空格。

你絕不能輸出任何東西叫header()

而且之前的文件編碼爲UTF-8 without BOM

+0

如果我想設置字符集 mysqli_set_charset() ..它顯示未定義的錯誤,這就是爲什麼我刪除部分代碼 – 2013-02-20 12:24:21

+0

可見(由系統回顯)錯誤也是輸出。 – vikingmaster 2013-02-20 12:26:00

+0

不,db.inc .php中沒有空格。請幫助 – 2013-02-20 12:26:56

0

如果你不能找到空白或者腳本做輸出,將此線在你的腳本的頂部:

ob_start() 

然後,你需要這個功能也可以是任何退出前();

ob_end_flush(); 
+0

我已經試過了...沒有爲我工作:( – 2013-02-20 12:39:37