danforys.com

Dan is a web developer in London. He is interested in all things Internet, Linux and Mac.
  • Fixing a bricked D-Link DSL-G624T

    Posted on January 22nd, 2010 Dan No comments

    My Parents have a D-Link DSL-G624T ADSL modem/switch. Unfortunately, my brother decided to update its firmware, crashing it in the process. After a bit of remote debugging over the phone, we thought the best option was to send it to me.

    The symptoms were as follows: The power LED came on as normal, the status LED was flashing as normal - indicating that it was at least booting up. The LAN link LEDs would light up when an ethernet cable was plugged in. However, its web administration panel couldn’t be reached on http://192.168.1.1 and it couldn’t be pinged either.

    After a lot of searching, reading and failed attempts at repairing it, I have found a method to reset the firmware without the web interface. Quite why D-Link make it so awkward for their UK customers, I don’t know.
    Read the rest of this entry »

  • Learning PHP - Part 6: Functions

    Posted on November 3rd, 2009 Dan No comments

    Functions are a very important PHP feature, and are the building blocks to some very powerful programming techniques. First of all, what is a function?

    In the tutorials so far, the PHP scripts have run from the top down. All instructions are performed in the order they appear in the file.

    A function can be thought of as a reusable ‘black box’. You (optionally) give it some data (called arguments or parameters), it performs an operation and (optionally) gives you a result.

    This is illustrated in the following diagram:
    function

    Read the rest of this entry »

  • Learning PHP - Part 5: Your first dynamic web page

    Posted on November 3rd, 2009 Dan No comments

    After the previous parts of this tutorial, you should be familiar with PHP variables and arrays.

    Now we will use these concepts to actually make a working web page. This page will contain a form that you can submit, and we will write PHP code to handle the form contents.

    Read the rest of this entry »

  • Learning PHP - Part 4: Controlling flow

    Posted on November 2nd, 2009 Dan No comments

    So now we’ve looked at variables and arrays, it’s time to make the code a little bit smarter.

    We’ve already seen how the foreach() can loop (iterate) over items in an array, but there are other ways to alter the flow of the code as well.

    Conditional

    One of the most common PHP statements is the “if”. In a nutshell, “if” does the following:

    if (some condition is true) { run this code }

    Read the rest of this entry »

  • Symptoms of a Wordpress Hack

    Posted on November 2nd, 2009 Dan 2 comments

    I came to my site on Sunday morning ready to write the latest in my PHP tutorial, only to find a nasty looking 500 server error. I couldn’t even log into the admin panel.

    After a while tinkering with various configuration settings and trying to get something to come up, I started searching the web. Turns out, earlier versions of Wordpress were vulnerable to specific hacks that could let attackers create their own admin users.

    Read the rest of this entry »

  • Learning PHP - Part 3: Array basics

    Posted on October 26th, 2009 Dan No comments

    In part 2, you were introduced to the concept of variables and the string, integer and floating point types. In part 3 we’ll go through a more advanced type; the array.

    Read the rest of this entry »

  • Learning PHP – Part 2: Variable Basics

    Posted on October 25th, 2009 Dan No comments

    After part 1, you should be familiar with the echo statement, which outputs a string to the browser:

    echo 'This is a string';

    (Note that from now on the opening (<?php) and closing (?>) PHP tags are omitted from examples, but should still be included in any source code you create)

    On its own, it does not appear to be useful; after all we could have just written ‘This is a string’ in HTML for the same effect. The real power comes from using PHP variables.
    Read the rest of this entry »

  • Learning PHP - Part 1: Introduction

    Posted on October 24th, 2009 Dan 2 comments

    So, you’ve got to grips with the basics of HTML and CSS, and now you want to actually make your web page do something? Well, PHP is a great way to do that. In this series of blog posts, I will introduce the PHP language and teach many useful techniques that are used in professional PHP development.

    Read the rest of this entry »

  • Unsetting http headers in PHP

    Posted on August 6th, 2008 Dan 3 comments

    I just came across a subtle issue affecting Internet Explorer users (well, fancy that!) and HTTPS connections.

    One of my clients has a site that downloads a series of results as a CSV file, which they open in Excel. Unfortunately, Internet Explorer was refusing to download the file, and was presenting an error message reading “Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found.”

    To add to my confusion, this was happening on the live server (PHP4), but not on my dev server (PHP5) which both use the same code.

    In the end, I happened upon a Microsoft Knowledge Base article that explained the problem. Basically, IE obeys any “no-cache” headers you send to the browser. Without caching the file, Office applications cannot open the file when served over HTTPS.

    How to solve the issue? Remove the cache header(s) - but how?

    The PHP manual doesn’t make it entirely clear, and I found the solution by accident. To remove a header, use the same syntax as for setting a header, but only include a space after the colon.

    For example, for the “Pragma” header:

    header('pragma: ');

    Note: You must include the space after the “:” or the header will not be unset.

  • Intermittent 1px gap in Firefox 3

    Posted on July 30th, 2008 Dan No comments

    My work has just pushed out an update, upgrading our users to Firefox 3. Naturally, we’ve been busy looking through our internally produced sites to check all is fine in the new version.

    In 99% of cases, all our sites look the same in Firefox 3, apart from one notable exception. In this one case, there is a 1px gap between the left-hand margin (which is centred using “margin-left: auto”) and the header image. Being the perfectionists we are, we don’t want a 1px white gap in our nice header.

    Oddly, this 1px gap would come and go as the browser window is horizontally resized. This behaviour set alarm bells ringing that it’s some kind of rounding error in the “auto” positioning vs the exact pixel dimensions of our centred container.

    After a bit of searching, we found an entry in John Resig’s blog (of JQuery fame), where he has stumbled upon the issue and developed a test case for the main browsers. Turns out that fixing it is a challenge, as all the browsers round the numbers differently. Problem is, there’s no standard for how the browsers should round the pixels, so fixing it in one browser will almost certainly break it in another.

    Ho hum, here’s hoping for a future standard.