Make sure you exit after a PHP Header Location

We came accross a bug in a bot filtering page the other day. The page called a routine which used a regular expression to check for validly formatted input. The function was called from several places and worked fine. In just one branch it appeared to fail to validate the input, and continued execution of the page instead of redirecting to the target page.

The reason? Someone left out the exit; after the Header Location call, which allows the execution to continue down the page. Moral: Make sure you call exit after a PHP Header call to Location if you want execution to branch immediately!

Getting Started With PHP

Getting started with PHP is a challenge just like any other programming language, but don’t let that stop you! There are plenty of resources for the experienced programmer looking for a technical solution, but they are too techey for the newbie just starting out. This post is a good place to start with PHP and lists some useful PHP resources to help you.

PHP is a powerful server-side scripting language for creating dynamic and interactive websites. Server side means that it runs on the server hosting the page, rather than the client or browser. PHP is widely used, partly because it is free, but mainly because it provides a fast and efficient alternative to competitors such as Microsoft’s ASP. It also supports database access easily and with much fewer lines of code than ASP. PHP is perfectly suited for Web development and can be embedded directly into the HTML code.

One place to start is the PHP manual, which unsurprisingly has a Getting Started section. My advice is to scan read as much of this as you can before attempting to start programming in PHP. It will explain what PHP is and can do, and then gives you a simple tutorial.

Click here to visit PHP manual

Another good place to start learning PHP is the PHP Tutorial on the w3schools website. This provides a complete references of all PHP functions and some user friendly cross links to functions that you may not even realise that you will need.

Click here to visit W3Schools PHP section

If you are new to PHP programming check out Getting started with PHP

Widgetizing Themes

We came across this really helpful resource on codex.wordpress.org which tells you how to fix up your WordPress theme, and make it Widget ready. Widgets are now a standard part of the WordPress install so to reach the broadest audience all modern themes should support them, as well as supporting old style sidebars.

You need to know PHP, HTML mark-up and CSS to benefit from this resource, but if you are in to writing your own WordPress themes, then you probably are up to speed with these anyway. If not you will need to be, so why not get cracking now and learn?

Click here to learn how to Widgetize your WordPress theme