11.3. Managing Redirection
The cart.5
script shown in Example 11-6 is a central point that
manages redirection to other scripts in the winestore. All pages that
have more than one button request this script using the
action attribute of the
<form> element. The script processes the
requests, determines from the GET method
attributes which script should be requested next, and then redirects
the browser to that script.
For example, if the user clicks the Empty Cart button on any page,
the following URL is requested:
http://localhost/example.cart.5.php?empty=Empty+Cart
The cart.5 script is then processed, the
following if test is found to be
true, and the script redirects to the
cart.4 script:
// Did they want to empty the cart?
if (!empty($parameters["empty"]))
{
// Redirect the browser to the empty page
// using the HTTP response header "Location:"
header("Location: example.cart.4.php");
exit;
}
When redirecting to some scripts, the redirection also passes on the
entire QUERY_STRING—the query string is
stored in the PHP environment variable
$QUERY_STRING—as a GET
method parameter. In addition, a session variable,
referer, is registered in selected cases so that
in later processing the script can redirect to the original calling
page.
As discussed in Chapter 10, there are several other
possible approaches for managing requests for different scripts
throughout an application. An alternative to the approach is to add
each button to the HTML page as a separate
<form> element with its own
action attribute. Other approaches include using
embedded links or images instead of buttons.
 |  |  | 11.2. The Shopping Cart Architecture |  | 12. Ordering and Shipping at the Winestore |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|