The singleton design pattern is used to centralise an object in an application that is used to store changing variables that can then be accessed by other parts of the program. It allows only the single instantiation of an object, hence the name.
Because it is possible to mask your user agent in Opera it is necessary to detect this browser first. There are actually two different ways to hide the user agent in Opera. The default user agent is as follows:
Every time you accept any input from a use you should attempt to validate it. This is to stop users trying to break the site and also corrects silly mistakes that users might introduce to their input.
Before sending off an email to a new user congratulating them on signing up it is best to validate that email address. Here is function that does this.
To find duplicate values you need to use the MySQL COUNT() function and then pick out all of the counts that are greater than one.
The Exif/IFD0 functions in PHP work with images to pull out meta data associated with them. Most image applications and digital cameras will produce an image with a certain amount of meta data present. This is obvious stuff like file size and creation time stamps, but you can also get stuff like copy right notices, camera name, date picture taken and even things like location if the camera was linked to a GPS system. This meta data can be used to sort or categorise images.
Using MySQL as a database engine in PHP is very powerful, but one thing that can be a pain is trying to debug code. Spotting the difference between a PHP error and a MySQL error can be hard with larger systems.
A good way of debugging MySQL code is by using the mysql_errno() and mysql_error() functions. These functions print off the last error that yuour MySQL server encountered so it can tell you exactly what is wrong with your SQL statements.
To detect a user returning to a web page you can use the built in PHP session manager. At the start of the code you can use the session_start() function to initiate the session, you can then use the $_SESSION global array to store and retrieve information. The session_start() function sends a cookie to the client with a unique code that looks like this
Sometimes is is necessary to see how long your PHP code runs for. This can be done using the following function and examples. This will convert the result of the php function microtime() into a float value.
For many sites the blog is only part of the site, not the main reason for the site existing. In these cases the blog is kept in the directory /blog or similar. Occasionally (for what ever reason) it might be necessary to change the directory. To that end here is a small walk through of the steps you need to take in order to do this.
Generating CSS with PHP has several benefits. For example, you can keep all of your colour declarations as PHP variables so if you need to change any colours it only takes a small edit and not a find/replace operation.
Getting PHP to generate CSS requires just two steps. The first thing to do is to open your CSS file and insert the following line at the top. This tells the browser that the file is CSS.