PHPBuilder - Mini Shopping Basket with only PHP4 Sessions



RSS Twitter
Articles Application Architecture

Mini Shopping Basket with only PHP4 Sessions

by: Evert Smith
|
August 17, 2000

Introduction

If you haven't done your own shopping basket with PHP yet, you should be able to build one after reading this article. Even if you have a basket already, some of the tips I provide here could help you improve your system.
I will give you some hints about how you could perhaps save yourself endless queries to the basket table or having endless text files that fill up your file system, because the application just does not remove them.
If you're new to this sort of topic, don't be scared. It is actually very simple and effective, all you need is a host that supports php4, some html editor like notepad or vi, some minutes of your precious time, and this little example.

The Idea

In 1998 a friend of mine working at a hardware store asked me to code an online shop for them. It needed to be fast and simple, with online administration. I get rather creative when running a 39deg Celsius fever, so I wrote that thing in perl, using minisql as a backend. During the process I put in what I refer to as a minibasket.
This minibasket is just a smaller variant of the regular shopping cart, showing you the contents of your cart on each page, without you having to jump back and forth to the cart after you've put an item into it. That's the idea I picked up for this article.

The Goal

People like control, so why not give them transparency and let them believe they have control? This minibasket is a perfect way of providing people with the needed information and also saving them 1 click, getting closer to the 3-click paradigm for online shops.
So, the goal is to show this minibasket on a part of your page at all times, a summary at the end to modify the items in your basket and finally to send of an order.

The Requirements

You should know about sessions. If not, here a quick rundown. There are many articles about it already, to find all the examples of code you need. Open a session on your start page with:

<?php

session_start
();

?>
This will create a session name and a session id. You now either use the default by setting session based cookies, pass the session id on with post through a form or attach it as variable to your link (get-method). Don't forget to destroy the session at the end. :)
Your articles should have a name and price and a unique identifier to work with this example, if not, you may want to modify it a bit. I used mysql for backend here, to build the pages etc, this is not required for the basket to work though. :)
You should know about arrays. Now if someone has the time to take my code and create a class of it, I'd certainly appreciate to have it.:)

1
|
2
|
3
|
4
|
5
Next Page »

Download: evert20000816.zip

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Evert Smith

Comment:



Comment:

(Maximum characters: 1200). You have characters left.