John Knowles - Development Blog

PHP 5 from PHP 4 - My transition to registered globals:off

Post by: John Knowles On 2006-11-03 12:01:41

As some of you may know there are quite a few transitions between PHP 4 and PHP 5. As I have just changed hosting companies and my new host supports both PHP 4 and PHP 5 I decided to upgrade.

At first I thought this would be an easy transition (I had lured myself into a false sense of security) and uploaded my site. To my surprise non of it worked.

I looked into my code and realized it was pretty badly wrote as I didn’t name the globals I was just saying $hello rather than $_GET[hello] if I wanted to get the data from the URL.

So I set about going through all my code changing all the variables to global variables and low and behold my site was fully operational again. I then went to login to my my blog system (Which I also wrote as i’m not much of a fan of using an open source blog. which would be overkill for what I want and I also wanted to keep my site pretty simple looking) and just kept getting the HTTP Authorization login. This confused me at first but I looked at the code and did a bit of research into the $AUTH variables and added the simple $_SERVER around them. I then upload and try to login and get the same thing.

I spent hours trawling through the code trying to find where the error was and spent even longer adding error reporting systems all over the place with it but I had no success.

Today I was that sick of not being able to update my Blog I decided to write a new login script using cookies as I also get bored of having to login every time I update, when only I used my laptop.

The new login system took about 5 hours to write including debugging. I did no note planning of this script and surprisingly it worked without much major alteration. Just a tweak here and there to make it more secure.

I can now finally login to my blog and portfolio system and update.

I would post my script but it would make my home page about 5 pages long and I’m sure someone would have all too much fun ripping into it and finding a hole.