Main Content

Howto - write and manage a news box on your web page

Archive - Originally posted on "The Horse's Mouth" - 2008-09-06 10:46:23 - Graham Ellis

Q: "I want a Content Management System. What should I select?"

A: I don't know - without asking you further questions!

The web, these days, is mostly about content management, and you may as well say to me "I want to get from 'A' to 'B' - please provide a way." I will have to ask you if A is just along the hallway from B (in which case all you need is a key), or it could be that A and B are on different continents (needs airline ticket, passport ...)

The most common CMS requirement of all is for a single page with content that's mostly static, but where a "latest news" box can be changed as required by the non-technical customer. Such a requirement can easily be met with a few lines of PHP, and I wrote an example during yesterday's course as a demonstration. You can see the page here (opens in separate window) as it's seen by the regular user. By adding an extra code onto the URL, though, it's provided with an exit box too - here - in which you can change the text and save it.

Regrettably, not everyone online is benign, and you need to be very careful to consider the security of even a simple application like this. In ours, the data you enter is "scrubbed" clean before it is echoed to prevent many attacks, and of course you should keep your back door / password secret and not publish them in a public page link (like I have done in the paragraph above!). However, these issues are easy to overcome if you take the right advise and think them through carefully.

If you want to learn about the techniques I've described above, you can have a look at the complete source code here. We also offer PHP Programming courses which cover the subject background or if you're looking to go more advanced, we'll actually be using this example as the start of our PHP Techniques workshop the week after next!