Hi,
I'm redirecting to a different page though I notice that the url stays the same...
Here is the code in the first page:
<?php session_start();
$fileName = "activeData/".session_id().".txt";
if ($action == "addToCart") {
if(file_exists($fileName)) {
header ("location: /basketConfirmation.php?action=addToCart");
} else {
touch($fileName);
chmod($fileName, 0755);
header ("location: /basketConfirmation.php?action=newCart");
}
$filePointer = fopen($fileName, "a") or die("Not available to write database...");
$newAdditionSub = ($numberOfBottles * $bottlePrice);
$orderComplete = "/beerDetails.php?uniqueId=".$uniqueId."&beerName=".$beerName."|".$beerName."|".$numberOfBottles."|".$bottlePrice."|".$newAdditionSub."";
flock($filePointer, 1);
fputs($filePointer, "$orderComplete\n");
flock($filePointer, 3);
fclose($filePointer);
exit;
} else if($action == "showBasket") {
if (file_exists($fileName)) {
header ("location: /basketConfirmation.php?action=showBasket");
exit;
} else {
header ("location: /basketConfirmation.php?action=noCart");
exit;
}
} else if($action == "delete") {
$file = file($fileName);
$removedLine = array_splice($file, $deleteThisLine, 1);
$f = fopen($fileName, "w");
foreach($file as $line)
fputs($f, $line);
fclose($f);
header ("location: /basketConfirmation.php?action=delete");
exit;
} ?>
The code in the second page then displays the contents of the basket and adds different text depending on what action had just been executed:
<?php session_start();
require("includes/markUp.php");
require("includes/basketThings.php");
$pageName = "Your Shopping Basket";
$metaKeywords ="";
$metaDescription = "";
$pageOfInterest = $PHP_SELF;
pageHeader($pageName,$metaKeywords,$metaDescription,$pageOfInterest);
sideMenuHeader(); ?>
<b>Search</b><br>
We have <?php include("includes/beerCount.sht"); ?> beers in our <a href="/downloads.php?file=beerSpreadsheet.txt">database</a> from around the world. Type your keyword below, choose your search category and click the search button.
<?php include("includes/search.php"); ?>
<b>Register</b><br>
To register all you have to do is fill in the simple form below. For more information about why you should register please read the 'Benefits of Registering' section to the <a href="/">homepage</a>...
<?php include("includes/register.php"); ?>
<?php sideMenuFooter();
print "<h4>Your Shopping Basket</h4>";
$fileName = "activeData/".session_id().".txt";
switch ($action) {
case "addToCart":
print "You have just added <b>".$numberOfBottles." ".$beerName."</b> to your order at <b>£".number_format($bottlePrice / 100,2)."</b> each.\n";
print "<p>Your basket currently consists of the following items:";
showBasket($fileName);
break;
case "newCart":
print "Your basket has been created and the following has been added:";
print "<p><b>".$numberOfBottles." ".$beerName."</b> at <b>£".number_format($bottlePrice /100,2)."</b> each.";
print "<p>If your order is complete you may checkout - if you would like to order more beers, please search our database using the form on the right or visit our <a href=\"/popularBeers.php\">Popular Beers</a> page for recommendations.";
break;
case "noCart":
print "Your shopping basket is currently empty. If you would like to order some beers, please search our database using the form on the right, or visit our <a href=\"/popularBeers.php\">Popular Beers</a> page for recommendations.";
break;
case "showBasket":
if (file_exists($fileName)) {
print "Below are the items that are currently in your shopping basket. If you would like to order more beers, please search our database using the form on the right, visit our <a href=\"/popularBeers.php\">Popular Beers</a> page for recommendations or <a href=\"/checkOut.php?action=details\">checkout</a>.";
showBasket($fileName);
} else {
print "Your shopping basket is currently empty. If you would like to order some beers, please search our database using the form on the right, or visit our <a href=\"/popularBeers.php\">Popular Beers</a> page for recommendations.";
}
break;
case "delete":
print "The item has been has been removed. To continue shopping use the search on the right - or <a href=\"/checkOut.php?action=details\">checkout here</a>.";
print "<p>Your basket now only consists of the following items:";
showBasket($fileName);
break;
}
pageFooter($pageName); ?>Sorry this is all a bit long...
Thanks.
Tony.