Putting the Snippets Together
Lets put the code together and store it as minibasket.inc
<?php
// remember the code from Snipplet 1, deciding whether to add or not?
// Let's repeat it here
if ($basket!=""){
//In here items will be added to the basket. let's check if there is already
//a basket registered.
if (session_is_registered("ses_basket_items")){
// There is a registered basket
// Place Snipplet 4 here. It adds the item to the registered basket, checks
// for duplicate entries, updates them or adds the item at the end of the
// arrays.
} else {
// There is no basket registered
// Place Snipplet 3 here. It creates a new basket and registers it with
// the session.
}
}
// All there is left is Snipplet 2. It displays the basket if there are items in it.
// Add it here.
?>
Et voila. “c’est tout”, as the French would say. If all is done right, you can store this
file as minibasket.inc and include it into your PHP Page where you’re showing the articles.
file as minibasket.inc and include it into your PHP Page where you’re showing the articles.
— Evert