UNIX Systems Administrator (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Mini Shopping Basket with only PHP4 Sessions
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.:)
[ Next Page ]


Comments:
ShopArmen05/14/08 13:01
RE: latest software of PHPprosenjit das11/16/05 01:52
Php shop Shopping Basket Problem marc11/01/05 07:28
weird cart showing upkitaeshi05/02/05 08:57
RE: Shopping CartAsia04/28/05 13:30
need help with basketRob04/13/05 03:45
page indexing in array ashramsuswal03/01/05 09:30
why ????wapweb02/17/05 23:22
how to add to the basket using java servletsarshiya02/11/05 00:01
RE: Adding, Deleting, Updating. Examples:tania12/11/04 00:51
RE: Adding, Deleting, Updating. Examples:tania12/11/04 00:37
RE: final version?Jim Fletcher04/11/04 21:40
Subject: Updatet Script to become class Gerrit ZAAIJER12/29/03 19:52
Link Doesn't WorkEvan08/27/03 21:15
RE: Error?Carl08/12/03 08:53
RE: Adding, Deleting, Updating. Examples:Heikki07/25/03 04:02
Adding, Deleting, Updating. Examples:Ben06/22/03 17:54
final version?Termee04/17/03 15:27
RE: Anyone using this on a site yet?Evert03/31/03 06:14
RE: Anyone using this on a site yet?Carlton Fletcher03/24/03 15:45
RE: How to remove products from Basket ????Stephen Robinson02/06/03 05:19
RE: Cannot send session cache limiteStephen Robinson02/06/03 05:17
RE: Delete in minibasketStephen Robinson02/06/03 05:15
hot to emptry whole basketStephen Robinson02/06/03 05:12
RE: Inputting data into a databasebruc wells01/20/03 10:11
RE: Here an example how to uise the classMatt Pritchard01/07/03 04:11
Simplest PHP4 shoping basketJoão Barradas12/23/02 14:38
I converted the basket for PHP4.20 and higherMarco Simons12/06/02 08:08
RE: cart using session arrayspunknroll10/24/02 12:03
cart using session arraysBenno10/20/02 03:52
Example using Classlsimon10/19/02 13:38
updatecart=0Lindsey Simon10/18/02 16:12
Here an example how to uise the classEvert10/18/02 11:40
example using new basket classlsimon10/16/02 20:38
answers to include, delete reload etcEvert Smit10/10/02 10:09
Click reload button on browserJason 10/08/02 14:04
Evert.inc ??Jens10/08/02 09:02
Error?Jens10/08/02 08:57
RE: deleting items from basketevelyn10/04/02 05:39
RE: how do you change # of certain productEvert Smit09/26/02 13:05
how do you change # of certain productDEREK09/23/02 18:35
Updatet Script to become classEvert Smit09/16/02 04:44
Deleting Items Indivually from the CartAndrew09/05/02 06:56
RE: totaling upAndrew09/03/02 15:20
Demo shopfrode nystad08/12/02 20:06
dont forget to put the session_start() at theEli Vaknin07/25/02 19:52
Good scriptUnknown07/14/02 16:37
How to make a Recurring Billing System w/ PHPNick06/25/02 06:02
Code in useAntonio "Antimax" Araujo06/21/02 23:09
RE: Shopping Cartcliffdweller06/04/02 20:44
Shopping CartDebbie05/28/02 20:35
totaling upHargs05/03/02 06:21
RE: what is the html code to add item to cart!Hargs05/03/02 06:16
porting this example to a php class with OOEvert Smit02/22/02 04:45
RE: what is the html code to add item to cart!Evert Smit02/22/02 04:36
RE: empty cart added and solved refresh problem.Evert Smit02/22/02 04:34
what is the html code to add item to cart!Rydell Shah02/18/02 12:07
RE: deleting items from basketJoeyG02/14/02 19:46
Ordering SystemDonna02/13/02 10:12
RE: deleting items from basketJoeyG02/12/02 18:46
RE: deleting items from basketJoeyG02/06/02 19:14
RE: what about the reload buttonJoeyG02/06/02 19:05
RE: Why the code does not workmike02/03/02 04:12
RE: empty cart added and solved refresh problem.Andrew Salmons01/06/02 16:27
php session shams12/27/01 04:50
coping with session expirationBen12/04/01 19:12
empty cart added and solved refresh problem.Zane Amiralis11/21/01 18:43
RE: Anyone using this on a site yet?tfg110/26/01 09:50
Regarding this exampleEvert Smit10/20/01 16:07
RE: Bad Idea here - InsecureEvert10/20/01 15:59
RE: help me out with this one pleaseEvert10/20/01 15:54
RE: Inputting data into a databaseEvert10/20/01 15:52
RE: Displaying the basket on a different pageEvert10/20/01 15:49
RE: Session vars get reset!Ian10/15/01 18:13
Session vars get reset!Ian10/15/01 12:18
Displaying the basket on a different pageLuke10/02/01 21:38
PHP4 Session classG|ga10/02/01 06:40
RE: Why the code does not workxinkun09/25/01 12:17
DESTROY THE SESSIONloreto mateu09/04/01 11:01
Inputting data into a databaseTom Hemsley08/29/01 08:11
how difficult is it to put up correct codes??viren08/21/01 22:35
help me out with this one pleasejoe Bestler08/21/01 09:33
Delete in minibasketjeff07/05/01 13:41
RE: Why the code does not workJohn McGarry06/25/01 07:53
not runningDino05/17/01 10:22
RE: what about the reload buttonChunhui05/16/01 10:25
RE: Sessions how...Jeff Lambert05/15/01 21:29
RE: Bad Idea here - InsecureJeff Lambert05/15/01 21:26
Sessions... Further in online/offlineRichard05/10/01 08:29
what about the reload buttonPitter04/29/01 08:16
RE: Bad Idea here - InsecureOllie04/25/01 17:21
Make some cents!!!Simon Pritchard04/02/01 23:06
re: bad idea, insecurefandelem04/01/01 22:41
Bad Idea here - InsecureTodd03/19/01 11:55
Item names with multiple wordsAndy Lewis03/04/01 21:39
Anyone using this on a site yet?Mike Seiler03/04/01 12:03
Cannot send session cache limiteMarc Weller02/28/01 03:33
RE: Cannot add header informationDaniel02/27/01 07:16
How to remove products from Basket ????Neville02/25/01 18:43
RE: Warning: var. basket is undefinedJahu02/23/01 08:26
Warning: var. basket is undefinedVictoria Afonina02/20/01 16:31
deleting items from basketBrian02/05/01 10:07
Warnings when starting..Hans-Jörg Alles02/01/01 09:40
RE: Why the code does not workeveral rimbald01/21/01 09:53
Willing to buy prepackaged codeRon Kwok01/05/01 10:28
Posting to different page.brian01/04/01 18:55
Why the code does not workGreg Militelo01/02/01 16:07
Zip fileStephanie12/27/00 14:14
Howto check for session without creating one?Jed Baer12/22/00 11:51
RE: Not WorkingGreg Trepanier12/05/00 14:14
RE: Cookie securityKeith Davis11/20/00 19:55
About cut and pasteFernando10/24/00 15:52
Strange script... - part 2 (read the end!)Jens10/09/00 16:22
Not WorkingChris Toole09/11/00 23:16
Cannot add header informationRandy09/11/00 11:27
RE: Sessions how...Martin09/07/00 03:21
RE: Sessions how...nico09/01/00 19:12
Security problem!spencer p08/31/00 11:08
RE: Browser's Back ButtomVincent Lam08/29/00 03:05
RE: Why can't I get it works ?Evert Smit08/28/00 16:39
RE: Cannot send session ?? please helpJames Hsieh08/27/00 05:14
Why can't I get it works ?James Hsieh08/27/00 05:04
RE: Cannot send session ?? please helpEvert Smit08/25/00 04:32
RE: Sessions how...Evert Smit08/25/00 04:29
RE: Browser's Back ButtomVince08/24/00 17:15
RE: Browser's Back ButtomVince08/24/00 11:50
Sessions how...Martin08/23/00 16:23
RE: Cannot send session ?? please helpMartin08/23/00 16:16
Cannot send session ?? please helpGorazd Majcenovic08/23/00 15:07
RE: Browser's Back ButtomRichard Heyes08/20/00 07:56
RE: Cookie securityEvert Smit08/18/00 06:03
RE: Browser's Back ButtomEvert Smit08/18/00 06:00
Browser's Back ButtomManuel Durán Aguete08/18/00 05:08
RE: Cookie securityMartin Wheatley08/17/00 12:49
Cookie securityVesa Nippala08/17/00 01:30
Yes, you can store objects.Robert08/16/00 11:15
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.