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.

Tuesday, 19 February 2008

I've just been dabbling with Apache's mod_rewrite functionality and it is super-sweet. It's one of those techniques that you just see everywhere these days.

I followed this example, which was easy to follow, to control the redirect.

I've implemented it on the tag system and also the categories and I'm really impressed with the results. Give it a try.



Tags: PHP Tags Blog Apache mod_rewrite .htaccess

Tuesday, 19 February 2008

I wanted to create a tag cloud, and looked at Cal Evans's Cloud Generator, which to me seemed overly complex, though very stable I'm sure. I just thought that it would be easier to work it out myself and tailor the solution to my needs.

It was actually easier to do than I thought.

  1. I run a query against the top 20 tags, returning the tag name, and usage tally, ordered alphabetically.
  2. I loop the results, adding them to two separate arrays, and calculate the maximum usage and minimum usage.
  3. Now I have the maximum usage value, I calcululate each usage as a percentage of the maximum, which I use to give the tag a rank 1-5. 0% - 19% is rank 1, 20% - 39% is rank 2 and so on.
  4. The tag is output as <span class="tag_rank_1"><a href="tagurl">Tag Name</a></span>
  5. In the stylesheet I set the styles I want for each rank such as darkening and enlargement of the font.

Click here for the source code.



Tags: PHP Tutorial Tags Blog Cloud Stylesheet

Monday, 18 February 2008

Due to a failure in the heating system in work today, we were all sent home early. In fairness it was bloody freezing.

After a 3 hour power nap, I got up and finally completed the tagging system for the blog.

It works simply though an onBlur function on an input box, splitting the tags into an array and inserting them into the database. Each keyword is passed separately so that I can check if it already exists in the database, in increment the usage accordingly so that I can later create a tag list, sized around popularity.  

It's a start anyway, and it works well, which is all I want. Off on holiday tomorrow, and hoping to be off Wednesday to help Lisa.



Tags: Javascript PHP Cold Work Temperature Tags Blog Split

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.

 

  1. When hitting the site, an md5 session key will be created and stored as a session variable.
  2. If the user starts a transaction, a database entry is created in a basket table, and the item is entered into an items table. Both the basket and the item entry use the md5 session key to relate themselves. One basket entry can exist to multiple item entries.
  3. The basket will exist as long as the session is active. 
  4. A cron job will remove non-complete baskets after several hours, keeping these temporary tables relatively clear.
  5. After checkout, the user selects the delivery options, then the order is sent through the google checkout api and the user continues to pay for their items.

 

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;

}

}

 



Tags: eCommerce PHP Shopping Tutorial
Featured Articles
Recent Articles