spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / carts / chap7 / 2 current pageTo page 2To page 3To page 4To page 5To page 6To page 7To page 8
[next]

Usable Shopping Carts, Chapter 7: CC Validation and Verification

Java Software Engineer / Architect Sr (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume
Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans


PHP/MySQL

[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">&nbsp;</td>

    </tr>

  </table>

  <table width="100%" border="0" cellspacing="0" cellpadding="0">

    <tr>

      <td valign="top">

home / programming / carts / chap7 / 2 current pageTo page 2To page 3To page 4To page 5To page 6To page 7To page 8
[next]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger

Created: December 26, 2002
Revised: December 26, 2002

URL: http://webreference.com/programming/carts/chap7/2/