continue reading hover preload topbar hover preload widget hover preload

Serving Files in Internet Explorer over HTTPS

Categories: Computers & Technology, PHP, Software, Web Development  |   No Comments

I recently came across a problem where serving a file to Internet Explorer would result in the following error message.

This affected IE6, IE7 and IE8 in my testing. The way I was serving the file was through PHP via readfile. Before sending the contents of the file, I was, of course, setting some header parameters so that the browser would handle the file and the user wouldn’t just see some binary garbage on their screen. In my case, I was serving a PDF file that was being generated server-side and sent to the client. The basic header parameters are as follows:

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called your_file.pdf
header('Content-Disposition: attachment; filename="your_file.pdf"');
// declare Files Size here (for the sake of peoples sanity, please add this
header('Content-Length: '.filesize($filename));

This works just fine in most situations, but once you introduce a secure connection, IE fails with the above error. Of course, like most IE problems, this doesn’t happen in any other browser. Ugh.

Asynchronous PHP

Categories: PHP, Software, Web Development  |   No Comments

I needed to “asynchronous PHP” recently and it took me a little while to find the solution. What my script basically does is generate a PDF file for the user to download based on some parameters they have chosen. The problem was, the PDF generate take a while and during that time I needed to show the user a screen explaining that the file was being generated, which would also show the download link once the generation was complete. My setup is as follows:

generate.php

This script is where the user is sent when they click “download” on the parameter choice page. This is where the asynchronous magic has to happen. From here, the user is immediately sent to download.php.

download.php

This script gives the user either a “please wait” message of a “click here to download” message, depending on where the target PDF has been generated yet.

My problem was, even though was added the header redirect code (shown below) to generate.php, the browser would still wait for the PDF to be generated before sending the user to download.php. In other words, it was only synchronous PHP, which didn’t help me at all.

header("Location: download.php");

Thanks to this comment on php.net, I was able to make it work! Basically, you need to tell the browser that you are done sending it data, even though the PHP script will keep executing. Code below:

//redirects the browser to the new url, but continues processing in the background
function redirect_and_continue($sURL) {
header( "Location: ".$sURL );
ob_end_clean();
header("Connection: close");
ignore_user_abort();
ob_start();
header("Content-Length: 0");
ob_end_flush();
flush();
session_write_close();
}

So, the user is sent to generate.php, which immediately calls redirect_and_continue(‘download.php’), redirecting the user to download.php while still continuing to execute generate.php (and make the PDF file). Once the user is at download.php, the script checks for the existence of the generated PDF file (as indicated by the filename sent through the session) and uses a meta refresh tag in the HTML to keep reloading download.php. Once the PDF file exists, it provides the user with a link to the PDF file for download.

Drupal’s On Hold

Categories: CodeIgniter, Drupal, Open Source, PHP, Software, Symfony, Web Development  |   No Comments

I know I said before that I would be replacing WordPress with Drupal around here, and I did start working on that. However, the more I read about Drupal, the harder it seems to do custom things. Actually, it’s more a problem of poor documentation than it is a lack of flexibility. Still, if I don’t know what I’m doing, it’s hard to learn anything.

Granted, I could easily replace WordPress for the sake of my blog here (and probably still will at some point), but that’s not why I was planning to learn it. I wanted something that would allow me to crank out new pages quickly without constantly restarting from scratch. I do have a very weak framework I’ve written to try to achieve this, but every time I start a new site, I feel compelled to re-do at least part of it, so in the end I don’t save any time. In fact, I lose time because I have to re-learn the changes I made for each site when I need to maintain them.

Farewell WordPress

Categories: Drupal, Open Source, PHP, Site News, Software, Symfony, Web Development  |   No Comments

In an effort to save time when I put together sites for people, I’ve been working on a universal engine I can use. It is modeled loosely off the MercuryBoard code and, for the most part, has served me pretty well. Recently, I’ve tried to revamp it with more object oriented code, integrating PEAR and a few other niceties. Still, the more and more I use it, the more I realize it saves me very little time. In fact, it actually costs me time when I have to go back and update the sites. It seems, sadly, the idea of a flexible CMS or framework is just too abstract for my skills.

I’ve spent some time reading about Symfony, which looks like an amazing project. I’m positive I can make it do anything I would need, but the learning curve is pretty steep and I’m worried that the time I’d take to learn it wouldn’t really pay off in the end. I like a lot of the concepts, but I’m just not completely sold on it.

So what does that have to do with WordPress? Well, I’ve recently revisited a project that I spent some time with in the past but never really did much with. That project is Drupal.

Configuring Access in MediaWiki

Categories: PHP, Software  |   No Comments

I’ve set up Mediawiki in a few times now, both at work and for personal use. Each time I do it, I end up having to learn how to set up access restriction again. That is, creating custom namespaces and restricting access to those namespaces to people that belong in specific groups.

The reason I do this is to keep of people out of articles that only privileged users should really be seeing. Articles about server configurations, software development, new ideas for sites, etc. Making a hidden namespace and allowing only specific groups to access it is the simplest way to go about this task.

Doing this is pretty straightforward. I won’t get in to all the specifics though; instead I’ll post links to the exact information you’ll need to pull it off.

User Rights
Custom Namespaces
Group Permissions
Setting permissions for a Group on a whole new Namespace

There you have it, nice and easy! Now I just need to fix/reinstall our personal wiki….