5.6. PHP ...at a glanceFrank hardly took any time in updating the placeOrder.php script. It still places an order, but now it doesn't need to return any HTML. Instead, it just gives an estimate for when the pizza will arrive at the customer's front door. <?php include("order.php");Frank's using a couple of other PHP files to handle order and delivery specifics. We won't look at those, but all these files are included in the book's downloadable examples. include("delivery.php"); // Error checking $order = $_REQUEST['order']; $address = $_REQUEST['address'];These just get the request data. if (strlen($order) <= 0) {Make sure we got an order that isn't an empty string. header("Status: No order was received.", true, 400); echo " "; exit; } if (strlen($address) <= 0) {This makes sure an address was entered. header("Status: No address was received.", true, 400);This sends a header back to the browser with an error message......and an HTTP status code indicating that an error occurred. echo " ";Some web browsers, like Safari, report a status code of "undefined" unless there is some response from the server. By sending a blank reponse, the correct status code will be reported by those browsers. exit; } // Place the order $pizzaOrder = new PizzaOrder($order, $address);The order is created, cooked, and then prepped for delivery. $pizzaOrder->cookOrder(); $pizzaOrder->prepOrder(); // Deliver the order $delivery = new Delivery($pizzaOrder); $delivery->deliver();The entire order is sent to the delivery boy, who takes care of getting it to the customer. $deliveryTime = $delivery->getDeliveryEstimate(); echo $deliveryTime;Finally, the script finds out how long it will take for the pizza to arrive, and passes that back to the browser. ?>
Answers on page 291. |