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

Oracle Report Developer (IL)
Next Step Systems
US-IL-Elk Grove Village

Justtechjobs.com Post A Job | Post A Resume
Developer News
ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow


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 >
Use Web Caching to Make Your Web Site Faster · Creating an Online Shopping Cart Mechanism in PHP · Log JavaScript Errors Using an AJAX-driven Web Service
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Configuring Granular Settings for a Database Level Audit · The Perils of a Web 2.0 Transition on Your Business Processes · Facebook Redesigns Site —Again — Nears 400M Mark

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

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