| home / programming / carts / chap7 / 2 | [next] |
|
|
[The following is a continuation of our series of excerpts from the glasshaus title, Usable Shopping Carts.]
The first item we need to take care of is terminating the user session so
that when the customer next returns to the site, he'll be assigned a new session
ID and start with a new, empty cart. That's the reason why we put the session
ID value in a hidden field on the previous page--so we could continue to
associate the customer with his cart and customer records while ending the
session. We want to call the session-termination code just once, when the
page ccform.php is first
loaded, and we don't want to execute this block again, lest we begin a new
session. To do this, we check to see if a POST
variable named cc_submit has been
set. If it hasn't than we know the user hasn't yet submitted the credit card
information form shown earlier, which means we're on the initial page load
and we should kill the session.
<?php
if( !isset($HTTP_POST_VARS["$cc_submit"]) )
{
First we call session_start() so that we can access the other functions and
variables relating to the session we're about to end:
session_start();
Following that, we call session_unset()
to unset any session variables--strictly speaking, we haven't set any of
those explicitly, but it's good practice to call the function anyway. Next,
we call session_destroy(), which ends the session by deleting any session
data stored on the server. We finish by deleting the session cookie if one
was used to maintain the session:
session_unset();
session_destroy();
if( isset($HTTP_COOKIE_VARS[session_name()]) )
unset( $HTTP_COOKIE_VARS[session_name()] );
}
require_once "../includes/db.inc";
require_once "../includes/location.inc";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TuneIn - <?php echo $title; ?></title>
<link rel="stylesheet" href="../styles/tunein.css" type="text/css">
</head> <body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> <!--Masthead table row-->
<td bgcolor="#CCCCCC" width="150" class="tunein">
<h1>Tune<em class="in">In</em>!</h1>
</td>
<td bgcolor="#CCCCCC" align="right"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
| home / programming / carts / chap7 / 2 | [next] |
Created: December 26, 2002
Revised: December 26, 2002
URL: http://webreference.com/programming/carts/chap7/2/