This site is a self-contained low down on what's going on in my life, what I'm working on, what I'm thinking about, and how I'm feeling about life in general.
Monday, 11 February 2008
This series of articles will cover the theory behind creating a simple eCommerce system.
Of all the components of an eCommerce site, the shopping cart will be the hardest to develop.
We will store an md5 session key that will link back to databased transactions.
It's easier than you think to build an eCommerce site, sometimes it's just having that guidance on process to complete it.
Below is some example code you can use to create and store your MD5 key.
session_start();
if($cartID == ''){
if(isset($_SESSION['cartID'])) {
$cartID = $_SESSION['cartID'];
echo 'Loaded from session: Cart ID: '.$cartID;
} elseif(isset($_COOKIE['cartID'])) {
$cartID = $_COOKIE['cartID'];
$_SESSION['cartID'] = $cartID;
echo 'Loaded from cookie: Cart ID: '.$cartID;
} else {
$cartID = md5(uniqid(rand(),true));
$_SESSION['cartID'] = $cartID;
setcookie('cartID', $cartID, time() +432000);
echo 'Created md5 key: '.$cartID;
}
}