php header redirect does not work
Here is the code:
<?php
$curDate = date("r",strtotime("now"));
if($database->addNewSale($_SESSION['username'],$_SESSION['userid'], $_SESSION['cart'],$curDate) ==10){
//Some of the offers in the cart have expired and cannot be purchased!
header("Location: ../order/index.php");
exit;
} else if($database->addNewSale($_SESSION['username'],$_SESSION['userid'], $_SESSION['cart'],$curDate)){
echo "insert process ok";
}
else echo "sale has not been saved into the db";
?>
But, when the function addNewSale
returns 10
which is the code for e开发者_C百科rror in cart, the redirect header function does not actually redirect to the page I set.
You have
header("Location: ../order/index.php");
But the location header is required to be a full absolute URL. I don't know if this is your problem but even if it happens to work it's not correct.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html section 14.30
Are you getting any warnings? header() failures are most commonly caused by the "headers already sent" warning, which can be caused by whitespace (can't have any of it above your php opening tag) or anything else that would be emitting to an html page. Check to make sure your text editor isn't saving it with byte order marks (BOM) - this causes the exact same problem as having errant whitespace. You can try turning output buffering on (ob_start() - just be sure to ob_end_flush() when you're done.)
First try with
if(result=='10')//use single quotes
otherwise
use full location path
$path="index.php";
header("Location:$path");
精彩评论