UKJester's "PHP" Rant
UKJester's adventures into PHP
What is PHP?
The first thing I discovered about PHP is that it's name is completely absurd! PHP stands for . . .
PHP: Hypertext Preprocessor
So, the first P in PHP stands for PHP!?!
Wikipedia has some geeky babble about PHP but basically it is a server side scripting language, which means any PHP code in a webpage is processed before the server sends the result to the users browser. You will never see any PHP code if you view the page source in a browser, only the results of what the PHP code did.
Anyway, you can search for PHP and read as much as you want later, you are here to learn about UKJester's adventures into PHP, remember?
What made me decide to learn PHP? One function alone clinched the deal for me. The INCLUDE function. I mentioned this briefly in my site updates, but basically, it meant I didn't have to keep updating the menu on every page each time I changed the site. I could INCLUDE the same Header and Footer files on each page, so I would only have to update 2 files. This is about as basic as you can get with PHP so it was a great start for me.
The conversion process from XHTML (which is really just strict HTML) to PHP was really easy. Simply changing the file extension of all my pages from .HTML to .PHP meant that I could then include PHP code in those pages if I wanted to. You can change the file extension even if you don't want to use PHP at all. It won't harm your pages, it just enables them to be more than they can be as HTML pages. The next step was to write some code, so my first ever piece of PHP code was . . .
. . . and it did exactly what I wanted it to. It sat neatly under the <body> tag and included my header at the top of the page.
After including my header and footer on every page, I decided to write a tracking script. This was just a few lines of code that I put at the very top of my pages. What it did was open a logfile stored on my website, and add some details to it, like the time, date, page name and referring page. This was great as I could now see what pages people were visiting, and map how they moved around my site, without knowing anything personal about who it actually was. To the script, each visitor was just "a visitor".
I was about to make my first error with PHP code. A very big error that taught me a valuable lesson.
What I did was add my tracker code to my error pages, specifically the 404 Page Not Found error. This was ok until I deleted the logfile that the tracker wrote the details to. When someone triggered a 404 error and my error page was requested, the first thing that happened was the tracker script tried to open the missing logfile. It couldn't find it so it triggered a 404 error, starting the whole process over again.
I was new to PHP and wasn't aware of the problems it could cause so I hadn't been checking the server logs. The first thing I knew about this was when my webhost moved my site to their testing server and emailed me, saying my site was generating several hundred simultaneous file requests (for the 404 error page) and that I needed to sort it out before they moved my site back to a live server.
This is when I accepted that I needed to actually learn PHP before I started playing around with it too much.
I have since learned quite a bit about how PHP works, and I am getting used to how the syntax flows. At the time of writing this, I have released (on my site only) my first PHP script. Below, you can find details of this script, and any others I have written since.
While writing my first real script, I realised that PHP was what I had been looking for since I stopped using my Psion Organiser donkeys years ago. I have always been a bit of a nerd and when I moved onto a PC I lost a way to write programs. Proper programs. I used to write small programs in basic back in the days of the BBC Micro (remember them?). As I moved up the scale of computers I lost the means to program. The BBC Micro I could program, the Vic-20 I could program, the ZX Spectrum I could program, the Commodore Amiga, losing the ability to program, but it could multi-task so I was sidetracked. By the time I got to a PC, I had lost track completely and really started missing being able to write basic programs. With PHP I can write as many if/for/and/else loops as I want!
I have now discovered that PHP can communicate with Databases, which opens up a whole new world of possibilities for my site (I am working on a script to remind me of special events now, check below to see how it goes).
UKJesters PHP Scripts
Contact Form (UKJSCF)
This is my very first real PHP script. Before this I just used to add small snippets of code to mainly HTML pages.
UKJSCF is very easy to customise, install and use. It's so good in fact, that I installed the script on this very site :)
This script was my first attempt at using PHP to interact with databases (SQL was completely new to me but as I was learning PHP I thought "What's another language?").
What does the script do? Well, it is to remind me of events. I can enter details of important events into a form, and save it to a database. I can view, edit and delete events. Every day, the script checks if any events, or reminders for upcoming events are due. The script then cheerfully emails me details of the things I need to remember, if there are any.
I really enjoyed making, testing, debugging, rewriting, cursing and finishing this script. I expanded the code into my first large PHP project, That Reminds Me but the site has since closed as only I used it :)
See 'Large PHP Projects' below for full details of how I turned this script into a fully functional website.
Large PHP Projects
That Reminds Me!
Ok, I'll give you a little background to explain why I started this project.
I have always been crap at remembering dates. The amount of birthdays that have completely slipped my mind is unreal! It's not because I don't care about the people, and it's not because I have a hectic lifestyle or anything like that. It's just because I'm crap at remembering dates!
I registered at a website called Memo To Me and entered all my friends and relatives birthdays and anniversaries and it faithfully sent me email reminders that helped me keep on good terms with everyone I care about.
I used the site for years but never thought I would get to a point where I could recreate my own version of it. When I joined the site I was still writing static HTML websites. Now I am teaching myself PHP and MySQL, and I have just completed my 'Event Reminder' script, I thought it was time to start a project I could get my teeth into, and that project is 'That Reminds Me!'
Ok, I started on 1st February 2010 by taking the 'Event Reminder' script I wrote with the idea of simply expanding it to enable more users. It didn't turn out to be quite that easy!
The last major update to the site was made in November 2010 when I rewrote a broken 'reset password' function.
The site is an internet application that helps you remember important dates, like birthdays. You enter a date in a form and some details about when you want to be reminded, and it, well, reminds you.
Some of the site features required me to :
- Create an automated sign up process.
- Create a secure login system.
- Devise a way to handle each user separately.
- Create and manage different user levels.
- Create and interact with databases.
- Deal with international dates, times and timezones.
- Create and send emails and SMS messages directly from the script.
Jumping in at the deep end, like I did, forced me to learn in a rather unorthodox way. I didn't start with the basics and slowly work my way up to more complex tasks. I picked a feature to work on and started with the hardest aspect of it, picking up basic functions and syntax as I went. It was a very sharp learning curve but I really enjoy the subject so it is a good way for me to learn.
w3schools was an invaluable reference during the creation of this application (site). I also signed up with a forum, DaniWeb, that has a great community helping with PHP problems amongst other things. I only asked a few questions but got a great deal of help reading other peoples posts and I eventually started helping other people out too.
The site has lots of great (and some rather cool) features that I am really proud of. Although the site can support unlimited users, it is really only me that uses it, but it's there if anyone finds it and likes it. I managed to implement almost all of the features that I wanted. There are still a few minor problems with it that I am working on every now and then. There is currently (March 2011) a major problem that has just come to light that makes one of the features unusable outside the UK, but as I am currently the only user there is no rush to fix it :)
I have mentioned this in my MicroBlog (also a PHP project) but as I am writing usable projects while I am learning, I keep wanting to rewrite everything with my new found knowledge. This is a never ending process as I am constantly learning. I have to learn to say "Make it work and leave it. Make the next project better. You can always rewrite the entire project in a few years if you want".
Update Feb 2012. It is now 'a few years' later so I am about to rewrite the entire project.
Started February 2010 - Completed(ish) November 2010 - Closed February 2012
LogIt is a project tracking/recording application. It allows you to log all the steps taken to achieve a goal, whether its find and squash a bug or write an application or rebuild an engine (not really, but you could do if you wanted).
When I started writing TRM I quickly realised I was going to need a way to record what I was doing, what I had done and what I still had to do. I started off with a text file to record what I had done, and post-it notes all over my desktop with what I needed to do. I then added even more post-it notes with details of the bugs that started appearing. I realised I could probably write a bug tracker but I was far too busy with TRM to start a new project.
I ditched the bug related post-its in favour of a ready made bug tracking script called FlySpray. This is a huge script (688 files, around 5 MB) with many more features than I really needed. I chose FlySpray because it was open source and because it was the one that seemed to have the least 'multiple user' options as it was just me using it and not a whole development team. Saying that though, it still has loads of multi-user features and it just feels too bloated for my needs.
After several changes, I settled on the name LogIt because it was designed to remove my need for text files and post-it notes by:
- Tracking bugs and what I do to squash them.
- Recording all the main steps I take while writing projects.
Although I didn't actually need multi-user features I decided to incorporate this from the start rather than trying to add it later. I am writing proper, complete applications here :)
I have almost completed LogIt now and I'm using it to record the final steps of it's own creation along with being a bug tracker for TRM and MicroBlog.
The project took less time and wasn't as complex as TRM but I still learnt a great deal about PHP and MySQL along with a surprise deeper understanding of CSS. I have a greater feeling of satisfaction with this project because it seems more complete than TRM, a lot neater. That's my growing but rarely sated 'just so' OCD showing there.
Started December 2010 - Completed(ish) June 2011
After answering a simple question on an online help forum, I became the main (only) coder for a new national lottery website (but nothing to do with Camelot).
The idea was great.
We would sign up 'Agents' that could be shops or charities or members of the general public. These agents would have a credit account with us and we would supply all the hardware (Smartphones etc) that they needed. The agents would sign up 'Players', taking payment and crediting the players account.
The player then signs up at our website and they can make entries into a weekly lottery using the credit they added via the agent.
- You are 7 times more likely to win £1,000,000 than with the National Lottery.
- Your chosen numbers are unique. Nobody will share your winnings.
- More money goes towards the winners payments.
- More money goes towards the charity payments.
- Less money is spent on admin. We use technology to reduce costs.
- You choose which charity gets your money.
The guy that had the idea, Clive, lived in the north of England and I'm in the south. We never met face to face but we did chat on the phone and exchanged hundreds of emails.
Clive had been working on the project for years and had sorted out all the promotion, marketing, legal aspects and insurance, connection to Paypoint terminals, payment to charities etc. etc. What he didn't have was a website that could handle public registration and account management. A visual way for players to choose their numbers and credit/debit their account. A site that could enable 'Agents' to sign up new players and credit their accounts via Smartphone apps.
In short, he needed all the 'website' parts of a website based lottery system.
- The 'Agent App' allowed agents to register players onto the system and add credit to their account. This credit was debited from the agents credit and was all tied in nicely to a database. Once registered, the player could go to any other agent and simply state their mobile number, or let the agent scan their member QR code and add credit to their account.
- The 'Player App' allowed members of the public to create an account and manage their personal details, chosen charity etc.
The framework was complete, the website was done, we were ready to launch, promote and start signing up agents. The project came to an abrupt end in August 2013 when Clive died unexpectedly!
Started October 2012 - Forced to end August 2013