當我發佈到這個腳本而沒有指定任何POST變量時,腳本仍然會重定向,但仍然會說。當我把die();在第一個if函數之後,頁面實際上被重定向。不等待代碼執行的PHP腳本
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$gender = $_POST['gender'];
$dob = $_POST['dob'];
$school = $_POST['school'];
$grade = $_POST['grade'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$test=FALSE;
$required = array ('firstname','lastname','email','phone','gender','dob','school','grade','password','password2');
foreach ($required as $value)
{
if(!isset($_POST[$value]) || empty($_POST[$value]))
{
$test = TRUE;
}
}
if($test)
{
header("location:../register.php?error=1");
}
$id = getRand(9);
$conn = getConnection();
$check = saveUser($firstname,$lastname,$email,$phone,$gender,$dob,$school,$grade,$password,$id,$conn);
if($check)
{
header("location:../quiz.php");
}
else
{
header("location:../register.php");
}
你應該看看這個問題 - http://stackoverflow.com/questions/3553698/php-should-i-call-exit-after-calling-location-header - 你應該停止腳本執行後重定向,或者退出;或死() – DrBeza 2013-03-16 20:51:36