PEAR Date Daylight Saving Bugs

The clocks went forward in the UK last night and fortunately I was working on a site today which involved manipulating dates and times between timezones so I immediately noticed a problem in PEAR Date that I have been using without problems until now.

When converting between time zones UTC and  Europe/London there was no change in the date/time value. As we’re now into British Summer Time (BST), Europe/London should show as 1 hour greater than UTC (which incidentally is the same as GMT), so it seems like PEAR Date has a bug relating to daylight saving in the UK in 2011.

Looks like there’s a better way to handle time zones than using PEAR Date now anyway. I’ll write a quick post about using the DateTime class introduced in PHP 5.2 soon.

Update: Time Zone Conversion using PHP DateTime Class

UK dates and strtotime

In PHP, strtotime cannot parse the UK date format (i.e. 30/02/2011) as there’s no 30th month.

Here’s a quick fix I came across that seems to work for me (so far)… Just replace the “/” with a “-” before parsing with strtotime.

$timestamp = strtotime(str_replace('/', '-', '30/02/2011'));

Credit goes to Stefan Kunstmann.

Update:

Here’s the note relating to this on php.net…

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash () or a dot (.), then the European d-m-y format is assumed.

So looks like replacing the slash with a dash is the reliable and correct thing to do.

jQuery slideDown problem on IE7

Just run into a problem with IE7 when coding up a fairly complex web form that needs to shrink and grow depending on the amount of detail the user wants to enter.

After an hour of fiddling around and a bit of googling (looks to be plenty of others with a similar problem), it seems to happen when you .slideDown() an element that is relatively positioned.

The quick and painless fix that worked for me was to add zoom:1; to the style of those relatively positioned elements.

div.your_class{
    position:relative;
    zoom:1;
}

For info, I have not tested this on IE6.  IE8 worked fine anyway.

Where’s Fedora 14 System Rescue?

I’ve just finished troubleshooting some things on my server and one thing that held me up was finding System Rescue on the Fedora 14 CD!

Well this turned out to be because it isn’t on every Fedora 14 CD, you actually need the full fat 3.4GB install DVD! The Fedora Live CD does not contain System Rescue.

Here’s some links to the ISO’s on fedoraproject.org (with the System Rescue), to save you having to dig for them…

Fedora 14 DVD 32-bit

Fedora 14 DVD 64-bit

P.S. This may not have been the case on old versions of Fedora, but I think this is the same on Fedora 13 too.

Move your website properly using htaccess

Sometimes you need to move an entire website to a new domain name. There’s lots of ways to do this, but if you’re not careful you might end up losing or confusing visitors (and google). Here’s a quick tutorial to help you out…

Of course you could put a notice on your old site linking through to the new page on the new site, but that would be clunky. Also you could do a javascript redirect, but that’s not much better. Ideally you want to send visitors through to the new site so they reach the content they want before they realise they’ve gone to another domain. For this (assuming you’re using apache), my first choice would be to use the htaccess file.

Single Page Redirects

Redirect 301 /page.html http://www.example.com/page.html

The line above in a .htaccess file in the root of your old website will send people visiting a specific page, through to a specific page on the new site. If you’ve got lots of pages though, it’s going to be a real pain to list them all.

Entire Site Redirect

Redirect 301 / http://www.example.com/

This will redirect any traffic to your old site to the root of the new site. However, with htaccess we can do better than that…

Entire Site Redirect (Preserving Directories & Pages)

If you have mod rewrite setup in Apache, the following lines in your htaccess file will make sure people get taken straight through to the correct pages on the new site.

RewriteEngine on
RewriteRule (.*) http://www.example.com/$1 [L,R=301]

The last example will make sure that your visitors and search engines can find your new content quickly and easily. Also you may notice the ‘301‘ listed in all of these examples – this lets google and other search engines know that the move is permanent.

Swift Mailer with STARTTLS

I used to use Swift Mailer all the time as it is so easy to setup and configure but about a year ago switched to phpmailer as I had a new mail server setup with starttls that I wanted to use and whatever I did I couldn’t get it going.

Just recently been trying to improve the efficiency sending large amounts of emails which led me to revisit Swift… and remember why I stopped using it! Swift Mailer v4.0.6 does not support STARTTLS… however, we can make it do it with a few tweaks:

After a few hours of searching and experimenting I came across a patch written to add starttls support. I’d never done a ‘patch’ in Linux before but it was easy enough once pointed in the right direction.

For those unable to patch/not on Linux/can’t be bothered, I’ve packaged up a zip of Swift Mailer v4.0.6 with starttls added for download.

You use starttls in the normal way, check the example below…

$transport = Swift_SmtpTransport::newInstance('mail.example.com', 25,
    'starttls')
    ->setUsername('username')
    ->setPassword('password');

$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('title', 'message', 'text/html')
    ->setFrom(array('from@example.com' => 'name'))
    ->setTo(array('to@example.com' => 'name'));

$mailer->send($message);

Internet Explorer cannot download…

“Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.”

Seen this before? I have, and I recall it being a bug on IE6. I may have even worked around it in the distant past (and forgotten what I did) but recently I’ve had this error message again.

However, this time I was alarmed to find that IE7 was suffering this error when trying to download a file from a webpage. Previously I understood that I had this problem when trying to download on IE6 over https – still a problem but at least it is only affecting a much smaller % of users.

Few places seem to document a definite solution, only suggesting what ‘sort’ of thing may be causing it. There may be other reasons, but in my case (and I suspect the majority of cases) it is an error caused by IE6/7 (perhaps other versions too?) incorrectly interpreting a header sent when a php session is started. The reason a php session may be started when trying to download a file is of course if you’re pulling the file dynamically out of a database. This problem also only seems to happen over https.

The Solution

Anyway, after a bit of digging I found a solution. Add the following code to your php script before the session is started:

session_cache_limiter('none');

This did the trick for me solving problems on IE6 and IE7. I’ll leave this note for future reference and anyone else with the same problem!

Dreamhost

Recently I’ve found myself using hosting services more and more.  In the past I’ve almost exclusively worked with dedicated servers sat in the same building right next to me. To my surprise it has actually been a pretty good experience…

I’m yet to compare to other hosting services, but the basic dreamhost account gives you access to some pretty advanced functionality – including cron, fully custom DNS management (with unlimited TXT records!), FTP, SSH etc etc. The only drawback I’ve found is when needing to use a php library that was unavailable. Despite hours of trying to solve things, it just wasn’t going to happen. Also it’s not fantastic that of course you’re on a shared IP and that it’s possible for that IP to change!

I’m currently intending to use dreamhost to serve bandwidth-heavy files and manage the DNS of my websites, but use my own dedicated server for anything with long lists of specific server requirements. Using a hosting service also offers a great opportunity to create backups up in the cloud where you can be pretty confident they’ll not be lost.

Hello world!

This is just a first page to get started and make sure everything is working. Looks like it is.