Apr 06 28

Publishing on a given date

If you've ever taken a look at either the Life of Jalo or Jermut, you've probably noticed that both sites create a daily page for the picture/strip. The way I've created it is that each file that needs to be shown is saved with the filename simply as the date (e.g. 20060428.jpg is today's image in LoJ). This post will show you how the naive approach to triggering something based on the current date and time may backfire and how to solve it.

To prevent people from looking ahead of the current date I used a simple is statement that compared the date now to the image requested. If the imagefile's name was greater than the current date, a HTTP 403 error code is returned. The code looks like this ($showTime is the date portion of the filename):

      if (date('Ymd') < $showTime) {
	return 403;
      } else {
        …

Of course, by now all of you should be wondering exactly what is the timezone in which the date should change? Well, my intention was that we'd follow a Finland-centric approach to the whole thing and the new image would be visible at the strike of midnight in Finland.

This all worked fine until we moved our hosting from a Finnish provider to DreamHost. The Finnish provider's servers all used EET (Finland's timezone, UTC+0200) and date() worked just fine. DreamHost's servers naturally don't use EET as their default timezone and testing that everything works after I've uploaded an image was a bit too hard. Plus I like seeing the next days picture before I go to bed, or rather having Anna look at it and tell me if something's wrong.

Luckily PHP comes with the function gmdate() that returns the current date and time in UTC. Then, with some simple code we can convert the reference time to EET and we're back at the usual publishing schedule. After you know of the existence of the function, any problems caused by timezones can now be easily solved.

Apr 05 28

Secure PHP

For all of you out there who are writing PHP code, I suggest reading Writing secure PHP and its part 2 by Dave.
I also strongly recommend using something like the quote_smart-function described in the PHP documentation (scroll down to example 3) when saving user input in the database.
The importance of writing secure [...]

Continue reading Secure PHP »

Mar 05 23

WordPress hacking

I’ve been hacking WordPress during my vacation. The results are now up and available here with some documentation on what was done (and how).

Continue reading WordPress hacking »

Jan 05 27

Form elements as PHP variables

A discussion on how the requirement for brackets for form elements as a PHP array is actually quite useful.

Continue reading Form elements as PHP variables »

May 04 26

PHP, Arrays and URL matching

Well, Dave Shea just posted some PHP code that just begs to be worked on. It also raises a general issue that most beginning programmers face. If programming is not your piece of cake, then skip this ;)

Continue reading PHP, Arrays and URL matching »