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

Senior Lotus Notes Developer
AMS Staffing Solutions
US-MD-Baltimore

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

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]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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

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