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

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

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

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