Press "Enter" to skip to content

Month: November 2008

Book Review: php|architect’s Guide to E-commerce Programming with Magento

I’ve decided to switch the back end of my side-line e-commerce dance wear and leisure wear clothing site from ClickCartPro to Magento. Why? Well, Magento is cheaper (moot point as I’ve already brought the licence for ClickCartPro), Open Source (so’s ClickCartPro), is more flexible (so it seems), has more options and it’s another shopping cart system for me to learn and have experience with (plus it does seem to be growing in popularity quite a bit).

However, the switch has come with a price: it’s quite a complex bit of kit! So, since Waterstones had an offer on and I needed to buy some other books I purchased php|architect’s Guide To E-Commerce Programming with Magento from them (Waterstones’ price is £19.99 and Amazon’s is £18.99: both with free shipping. It’s also available as a PDF for $29.99 from the publisher’s site). Why did I buy this book? Well, it was the only Magento book Waterstones (or Amazon) had!

PHP: Zend Framework, MVC, Cookies and 4096 byte oddities

A little word of warning which has puzzled me for over 3 hours in debugging…

If you use Zend_Controller_Front::getInstance()->dispatch(); in your Zend Framework index.php file for firing off the MVC system, and the returned page is over 4096 bytes (4 kilobytes) in size you cannot set a cookie afterwards without causing the “fun” error “Cannot modify header information – headers already sent by (output started at …/library/Zend/Controller/Response/Abstract.php:546) in …”

To work around this, you’ll need to change the code from just:

Zend_Controller_Front::getInstance()->dispatch();
setcookie(. . .);

to:

$front=Zend_Controller_Front::getInstance();
$front->returnResponse(true);
$response=$front->dispatch();
#Zend_Controller_Front::getInstance()->dispatch();
setcookie(. . .);
$response->sendResponse();

I’m sure there is a slightly better way of setting Cookies in the Zend Framework, but that’s a work around for the normal way I’ve found.

If you’ve got any “better idea” suggestions, just let me know.

(I found this “buglet” because a drop down select menu I was making with Zend Form Element was causing the “Cannot modify header information – headers already sent by” error once a number of items were listed: it took 3 hours+ of detection work to narrow it down to a content size issue, then it was a process of elimination ruling out Zend_Form_Element, Zend_Form, Zend_View and Zend_View_Abstract (which helped a bit with the debugging on the issue) and then to Zend_Controller_Front to Zend_Controller_Response_Http and finally to Zend_Controller_Response_Abstract)

Snippet: PHP, MySQL and IDN Email addresses

Here’s something to look out for if you are building an international website where you are handling email addresses…

Email addresses, as you are probably aware, comprise of two parts. The “local part” (the bit before the @ sign) and the “domain part” (the bit after the @ sign). Therefore with the email address richard@example.invalid , “richard” is the local part and “example.invalid” is the domain part.

The domain part of the email address can actually be 255 characters in length theoretically (it’s 63 characters for the actually domain name, then the TLD: however, you could have sub domains in force which can take it up to the 255 limit.

The local part of the email address can be 64 characters: bringing the count up to 319 characters. Allow an extra one for the “@” sign and 320… Just slightly too big to fit within the standard 255/256 character string field that has tended to be used. I’ve seen rumours that this section may be expanded to 128 characters, so plan for 383 characters.

Oh – don’t forget that Internationalised/Internationalized Domain Names are becoming popular in some countries and unless you want to handle conversion to/from Punycode or another storage format for the IDNs, then you’ll need to make your database store the email address in Unicode… However, that appears to cause a problem in some version of MySQL if you store it all in a Varchar field.

So in your programming language (such as PHP), you’re going to have to keep all the above in mind and then split the email address into two parts for storing in the database for sanity.

See http://www.faqs.org/rfcs/rfc2821.html, http://en.wikipedia.org/wiki/E-mail_address, http://www.santosj.name/general/stop-doing-email-validation-the-wrong-way/ and http://askville.amazon.com/maximum-length-allowed-email-address/AnswerViewer.do?requestId=1166932.

Snippet: How To Tell if Your Cat Is Plotting to Kill You

Let’s face it cat owners, we all know the little fur balls are plotting on taking over the world (I blame the Egyptians myself!). When they aren’t asking “I Can has Cheezburger?, they are working out how to get rid of us humans. Lucikly, there’s a list you can work down to try and work out if the cute little ball of fluff is trying to kill you. There’s even a quiz for you to check – odds are that your cat is trying to kill you.