• The Boxhead Launch Checklist

    Posted on 9th Nov 2015

    Thousands of sub-standard websites 'go live' every single day. At Boxhead we wanted to make sure we didn't launch any of those websites, that offered so much but didn't deliver a great experience. But how do you ensure you're consistently launching top-of-the-line websites for clients across the board with multiple designers and developers in the mix?

    Let me introduce you to our answer

    The Boxhead Launch Checklist

    I know, I know it's just a set of tick boxes I hear you say. While that is true and anybody could have thought of it, nobody else did to my recollection and certainly not comprehensively.

    OK you might have a spreadsheet to track this sort of thing but that's not really what spreadsheets are for and you know it.

    The launch checklist has been around (in multiple versions) for a few years at Boxhead HQ. It's not special in itself, but it keeps us on track to deliver outstanding websites to all our clients every time If you're a client of Boxhead, big budget or low, your site has had the launch checklist treatment.

    The checklist has seen multiple versions as we've re-visited what it takes to make great websites in our ever-evolving landscape. We expect the checklist to improve as we learn day-to-day, as development best practices settle and as new tools become a part of our workflow. As it stands, here are some of the core areas the checklist covers:

    • SEO Best practices
    • Performance checks
    • CMS specific configurations
    • Accessibility standards
    • Compatibility
    • Security
    • Legal things...

    Why disclose our secrets?

    We use the internet almost every single day, accessing websites, web-apps and other online tools. We know the pains of visiting a site that could with very little extra time have delivered a vastly better and more appropriate experience. With so much practice under our belts of building and launching great sites it would be inexcusable for us to hold this tool close to our chests. We want to make the web better for everyone. We can't do that on our own. Share and share alike.

    Our hope is that developers the world over will adopt some of the best practices outlined in the checklist as part of their workflow. Not every item will apply to every project, that's OK. There are probably some items missing (we're not perfect – let us know how to improve it for everybody).

    Why not give it a whirl on your next web project and see if it helps you launch something fantastic.

  • Craft CMS image upload fails

    Posted on 29th Oct 2015

    Yep, I'm sure all Craft developers have been there at some point. You go to upload an image, you get the pretty progress bar, it gets to the end, and then nothing.

    There can be many reasons why this might happen. Here's my checklist:

    1. Is the upload directory writable?
      Fix: Check your directories permissions. It should be set to 775 or 777 (if you live life on the edge)
    2. Are the asset paths set correctly? You can find these in admin/settings/assets
      Fix: Check you have the correct absolute or relative paths and URLs set. If you're using multiple-environment configurations and are using variables like {basePath} and {baseUrl}, check these are correct in your craft/config/general.php file.
    3. Is it a PHP memory_limit problem? If it is, chances are there's an error logged in craft/storage/runtime/logs
      Fix: Get your hosting provider to increase PHP's memory_limit to 64MB, 128MB or 256MB (if you're feeling particularly adventurous)
    4. Is the upload script timing out? Again, if this is the case there could be an error indicating so in craft/storage/runtime/logs
      Fix: Get your hosting provider to increase PHP's max_execution_time
    5. If you've got this far and are still having problems you may need to use the following wizardry to get things working. I've had this problem when trying to upload JPGs (where every other file would upload fine).
      Fix: Get your hosting provider to update the PHP configuration (typically the php.ini file) by adding mbstring.func_overload = 0
      Thanks go out to 'Oliver' over on this Stack Exchange thread for that fix!
  • PHP $_POST converting array to string 'Array'

    Posted on 22nd Jun 2012

    I've been developing in PHP for about 5 years now, processing form data using $_POST on almost a daily basis. It was only yesterday though that I came across this little headache for the first time. What looks like and array, talks like an array, should be an array but is actually the 5 character string 'Array'!?

    Here's the scenario I was in. I was trying to post some fairly normal form submission data (a few text inputs and a checkbox array) using cURL to an API that would in turn update a database record. I would then expect a JSON result from the server letting me know if all went well or if we had any errors in the form data or updating process. Seemed straight forward enough.

    My basic cURL code was this.

    <?php
    $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.co.uk/api/update/format/json'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); $buffer = curl_exec($ch); curl_close($ch); $result = json_decode($buffer); ?>

    I've used this code a few times before, and even in the same project. But there was something going on this time that was causing some of the $_POST data that should have been an array, to actually be converted into the string 'Array'. Weird huh? Using print_r() and var_dump() on $_POST was showing me the right data in the right format. But if I returned the $_POST data from the API method and used print_r() on the $result variable it would show any array now as a string.

    More often than not Google will find me a result or something near enough to put me on the right track but after 3 hours searching I was drawing a blank! People had experienced similar issues previously but there never seemed to be a a solution by the end of the forum posts. Close to tears it eventually dawned on me that it must be something to do with the way cURL was handling multi-dimensional arrays. All my other forms in the project using the same code and that were working, weren't posting multi-dimensional arrays (an array in an array, for those not sure what on earth I'm talking about).

    A little digging around cURL quite quickly informed me that in fact cURL does not handle these sorts of arrays well at all. The fact still remains however that I needed to send this data through, so the question was how to convert a multi-dimensional array into something like a string that could easily be sent but then on the receiving end convert the string back into the array?

    Well fortunately the solution is not a complex one. PHP has 2 native functions that will do exactly what we need in this case, serialize() and unserialize().

    We need to use the serialize() function to convert our form data in the global $_POST array into its string representation.

    Simple enough, my new code is now.

    <?php
    $postArgs = array('data' => serialize($_POST)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.co.uk/api/update/format/json'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postArgs); $buffer = curl_exec($ch); curl_close($ch); $result = json_decode($buffer); ?>

    A new step is now required on our receiving end in the API method now to convert our string back to it's original array. So in the receiving method we'll use the unserlialize() function like so.

    <?php
    function update_post() { // Convert the $_POST data from string representation back to multi-dimensional array $_POST = unserialize($_POST['data']); /* * Validate and Sanitize form data then update Database Record */ } ?>

    So there we have it. The solution is a simple one but it was a real fight getting there. I hope it helps others who run into the same or similar issues.

    I only got through by the power of Yorkshire Tea and stroopwafels.