Dan is a web developer in London. He is interested in all things Internet, Linux and Mac.
RSS icon Email icon Home icon
  • 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.

  • HTTP Authentication in PHP

    Posted on June 12th, 2007 Dan No comments

    I’ve just discovered, totally by accident, how to get HTTP Authentication (when the browser pops up a dialog asking for the username and password – usually set with a .htaccess file) values within PHP. Previously, I’d just assumed that the authentication was a “black box” and I was unable to use it within my scripts. I had done some experimentation to see if any of the information was present in the _POST or _COOKIE arrays to no avail.

    Read the rest of this entry »