Installing Xdebug on Mac OS X

Date Icon Posted on Saturday 2nd February 2008 @ 6:16pm GMT

Xdebug is an incredibly powerful PHP extension that helps you debug scripts by providing a lot of valuable debugging information. It saves you from having to write your own debugging function for catching errors, at least during the development stage of a web application and certainly provides a lot more information than the standard PHP error messages!

Xdebug also provides the following: -

  • Stack traces and function traces in error messages with:
    • Full parameter display for user defined functions
    • Function name, file name and line indications
  • Support for member functions
  • Memory allocation
  • Protection for infinite recursions
  • Profiling information for PHP scripts
  • Code coverage analysis
  • Capabilities to debug your scripts interactively with a debug client

From the above you can see it's a very powerful tool that every web developer should have installed on his or her machine and is in-fact included with quite a few commercial IDE programs. Surprisingly, Xdebug is actually open-source, so without further ado... I'll show you how you can easily install it on your Apple Mac using pre-built binaries...

Problem with PHP mail() and Additional Headers

Date Icon Posted on Friday 28th September 2007 @ 8:47am BST

With the PHP mail() function, you can specify additional headers for the emails that you send. This is a very powerful feature, which lets you do things such as add addresses to blind carbon copy or specify which email address the email is coming from.

It’s great but the PHP manual says this about additional headers: –

additional_headers (optional)
String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).

Yes, so according to the manual multiple headers should be separated with CRLF (\r\n). However, if you try this on a Linux web server you will probably get some of your headers stuck in the body of the email! There is a quick and easy solution though...

The Secret to cURL in PHP on Windows...

Date Icon Posted on Sunday 20th May 2007 @ 11:48am BST

cURL is a great library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers using many different types of protocols. In particular, it’s used heavily in PHP to communicate to Payment Gateways and fetch XML feeds from other sites whilst being ‘transparent’ to web page visitors.

The particular secret I would like to share involves establishing connections to secure sites (SSL-enabled ones in particular). When you browse to an SSL–enabled site in your web browser, a few things happen... One of the things that happen is that your browser checks to see if the site’s security certificate is trusted. It does this by checking the entity that signed the certificate against it’s built in book of trusted signatures and if it finds a match, onto the next step. However, if your browser can’t find a match the certificate will be invalid and it will complain that the site could potentially be a fake or insecure.

Building upon Strong CSS Foundations

Date Icon Posted on Sunday 25th March 2007 @ 2:47am BST

If you design websites, you probably aim to make sure your site looks good in all the major browsers. Typically developers and designers will tend to start creating a site using Firefox to constantly refine the layout, partly due to the more reliable style rendering and the huge amount of extensions available (Firebug and Web Developer are two worth checking out).

Once the layout is ready, the next stage is making sure it looks the same in other browsers such as Internet Explorer, Safari or Opera. Something that will save you a large heap of time, is realising that a browser has its own internal styling rules which define things like how tall an H1 tag is or how much padding a list item has... unless you override the value in your CSS, it will use the internal default. Now you may be thinking that this on it’s own is pretty obvious and how can knowing this save you time? Well each browser doesn’t use the same internal styling rules and while they tend to be similar, there are always subtle differences... a difference that could cause you to curse and swear at your monitor because you’ve spent the past hour trying to get that menu to line up in both Firefox and IE when all that was required was to set the padding to zero!

Now imagine you could specify all the browsers to use the same internal styling sheet! You could then build your site’s CSS on strong, level foundations that are the same in all the major browsers, resulting in less work when it comes to cross-browser testing. :) In–fact you don’t even need to imagine because Yahoo have come up with the CSS reset – a single CSS file you link to before any other CSS and it gets you back to a level playing field! Yahoo have details of how to make the most of this file on their developer network and best of all - it’s free!

Total Lunar Eclipse 2007

Date Icon Posted on Sunday 4th March 2007 @ 11:10am GMT

Photo of Lunar Eclipse UK 2007If anyone were looking outside of their window last night, they would have seen a fantastic dusty red moon on a perfectly clear night. As the moon slowly hid behind the earth, I tried to take some photos using some binoculars... this involved quite the complex task of lining up and focusing both binoculars as well as my digital camera. Then once I'd kind of got it how I wanted the shot to look like, I had to work out how to press the shutter button!

Well, eventually after a dozen or so shots and a near miss with my camera and the patio, I did manage to get one good shot of the moon! This one can be found to the left.

Meanwhile, the BBC have some nice photos that the public have taken on their website. Enjoy :)

Buying Microsoft Windows Vista

Date Icon Posted on Monday 29th January 2007 @ 9:26pm GMT

Tomorrow Microsoft Windows Vista will be released to the whole world... all 6 editions of them! To celebrate this, the guys at The Joy of Tech have produced another great comic strip short. Enjoy :)

Vista Comic Strip short from joyoftech.com

Warcraft III is now Universal!

Date Icon Posted on Tuesday 23rd January 2007 @ 11:18pm GMT

Warcraft III is one of the classics. As Gamespot describes it... the game has lots of great characters, and its fantasy-themed world has tons of personality. It’s got fine-tuned, well-balanced game play, it’s got a quick pace, it’s got some game play twists that should surprise even the most hard-core real-time strategy gamers, and it’s simply a lot of fun... even after nearly 5 years since it’s release date.

It’s even more impressive to think that Blizzard, Warcraft’s creators still update the game – on Monday Blizzard released Patch Version 1.21. This finally allows the game to run at native speeds on both a PowerPC and an Intel Mac thanks to the game now being a universal binary.

The patch also applies a number of game-balances, crucial fixes and adds a new feature or two. Details of the patch can be found on the Blizzard Support Website.

Word Press 2.1 Released

Date Icon Posted on Tuesday 23rd January 2007 @ 7:16am GMT

The latest version of Word Press was released yesterday and features some interesting new features – autosave, lossless XML migration, an upload manager and redesigned login screens from the shuttle project to name a few...

A full list of the changes can be found on the Word Press Development blog and can be downloaded here.

Validating Credit Card Numbers

Date Icon Posted on Saturday 16th December 2006 @ 10:11pm GMT

Lately, I’ve been working on an e–commerce website and discovered a handy algorithm for validating card numbers. The Luhn algorithm (also known as mod 10) is a checksum formula and is used to protect against accidental errors rather than malicious attacks.

The algorithm is particularly useful for checking to see if the card number ‘looks’ right before sending it off to the payment provider for processing. This reduces the amount of rejected card payments, which is always a good thing :).

More details of how the algorithm works can be found on Wikipedia and my annotated PHP implementation can be found below.

/* PHP function for validating card numbers */
function checkLuhn($cardNumber) {
    // Copyright (c) Richard Warrender. Licenced under the LGPL.
    // http://www.vividreflection.com/

    // Get total amount of digits to process
    $digitCount = strlen((String) $cardNumber);
    // Checksum must be zero to begin with
    $checksum = 0;
    
    // Loop round card number extracting digits
    for($i = 1; $i<=$digitCount; $i++) {
            // Extract digit number
            $digits[$i] = (int) substr($cardNumber, -$i, 1);

            // Check to see if this the luhn number, we need to double it
            if(($i%2) == 0) {
                    // Double luhn digit
                    $digit = $digits[$i] * 2;
    
                    // If greater or equal to 10, then use sum of digits
                    if($digit >= 10) {
                            // Get first digit
                            $firstDigit = substr($digit, 0, 1);
                            // Get second digit
                            $secondDigit = substr($digit, 1, 1);
                            /// Add together and replace original luhn digit
                            $digit = $firstDigit + $secondDigit;
                    }

                    // Reload back into array
                    $digits[$i] = $digit;
            }
            // Keep a running total for use in checksum
            $checksum += $digits[$i];
    }

    if(($checksum % 10) == 0) {
            return true;
    } else {
            return false;
    }
}

Blue Screen of Death Saver?

Date Icon Posted on Thursday 9th November 2006 @ 1:02pm GMT

Someone at Microsoft has a very good sense of humor. They’ve released a blue screen of death screen saver... to remind people of the good old days. Only a matter of time before it gets pulled I reckon :)

Download it while you still can! ... More details can be found on The Register.