A quick search of the Internet will show that PHP is best described as an:-
“Open source general-purpose scripting language that is especially suited for Web development and can be embedded in HTML”
The term stands for PHP: Hypertext Pre-processor. It is important to note that only servers with PHP installed can read and interpret PHP scripts. To give you an example of the popularity of PHP, it is now standard with the vast majority of website hosting plans whether shared hosting, VPS, dedicated hosting or cloud hosting. It is also one of the most used scripts when it comes to WordPress, the most popular open source content platform in the world today.
There is an inbuilt system in the PHP script which allows you to track any errors. Then, once found you can make the relevant adjustments. It is worth noting that some server PHP installations will “switch off” the error display element. this is a means to protect the integrity of the server. However, there is also the option of tracking errors via an error log file. This log, allows you to see what kind of errors are occurring and how frequently.
PHP scripts may look fairly technical but once you begin to break them down it is fairly easy to read the database related errors and PHP warning vocabulary. We will now take a look at some of the more common PHP error messages that web designers should be aware of when creating what can often be dynamic tools for their websites.
Table of Contents
Locating the error log
As we touched on above, the most common way to report PHP errors is via an error log which can simply be opened up from the web server. This will show a detailed list of the type of errors which have occurred and is the base point for correcting the PHP code. The wording of the file should be fairly straightforward and easy to access, often in a stand-alone directory. It is worth password protecting the error log/directory so that hackers are not able to download this directly from the website. In theory, once they know the errors (i.e. the weaknesses of the code) they may be able to find a backdoor entry.
If you have any issues finding the PHP error log we suggest contacting your host provider for further information.
Blank screen
On occasion you will come across the dreaded blank screen when running PHP code alongside HTML. You will also notice that any attempt to view source code will have limited success because the error would result in the markup being cut off. The blank screen suggests that an error has occurred after some HTML code relating to the format of PHP code. It may be something as simple as missing a symbol from the PHP script but a quick look at the error log will point to where the error occurred and cast more light on the potential solution.
The first error is the most important
Upon experiencing a PHP script error you might be presented with hundreds and hundreds of errors on the PHP error log. This can obviously be concerning but you will often find that it is the first error that is having a knock-on effect and causing hundreds of other errors. Thankfully, in the vast majority of cases when you rectify the first error the rest will likely disappear. The best way to identify specific errors which are having a knock-on effect is to look at the time they were logged. Due to the speed with which your server operates you will notice groups of errors with the same time stamp. Pick the first error in this batch, rectify it and with any luck the rest should disappear as well.
Database related errors
The vast majority of PHP errors involve database connection issues which may involve the database username, password, server address and the database name. If any of these four elements are incorrect then no connection will be made and an error will be displayed. Some of the more common errors you will see include:-
- The User Has Entered Localhost Instead Of An IP Address Or URL For The Database Server
- An Incorrect User Name Has Been Entered
- An Incorrect Database Name Has Been Entered
Database permission problems
You will also come across situations where the username, password, server address and database name are correct but there are still connection issues. Some PHP scripts require permission to create additional tables based upon information from the database. If the user is not set up with the required permissions this will create an error and the PHP script will not work correctly. There is a very easy way to resolve these types of database related errors; tick the relevant box and add the privilege to the user.
PHP error Messages
While database issues tend to be relatively easy to resolve, on the surface it can look a little trickier to resolve PHP errors. However, once you understand what the errors actually mean, this is a whole different ballgame!
1. Fatal Error: Call to Undefined Function
In short, this error occurs when the PHP function detailed in the PHP script cannot be found. This is a common problem when installing a third-party script if. Here, for example are some reasons why this error emerges:
- All of the files relating to a new script have not been uploaded
- On upgrading a PHP script one of the files has not been replaced
- A missing PHP include or incorrect path in a configuration file
- Attempting to use a PHP function not available on your server
This type of error is simply down to a missing file, or missing upgraded file, which can be fairly easy to resolve. There will be occasions where commands are missing from your PHP installation; perhaps you are still using an older version, which may need the assistance of your hosting provider to resolve.
2. Fatal Error: Cannot Redeclare
You will likely find that this type of error occurs when you have included a file twice within your script text. It is simply a case going back over the code to check included files and make sure there is no duplication.
3. Fatal Error: Allowed Memory Size Exhausted
This can be a fairly common error when trying to upload/process an image which may require significant memory capacity to run. The allowable script memory capacity is set by your host provider and if additional capacity is required they will need to make the adjustments.
4. Permission Errors
At some point it is highly likely that you will come across various permission errors which relate to individual directory permissions. The configuration is fairly easy to adjust. Though, you need to be aware of the power of allowing write-to file options.
5. PHP Warning: Include
This PHP error message is interesting because it is not an error as such, it is a warning. The script will literally move on to the next command and continue trying to load the page even if it cannot find the include file. This is where you are likely to get formatting errors and non-fully functioning pages.
Step-by-step PHP error resolutions
It is impossible to cover all of the potential errors you may encounter with PHP script. What we do know is that PHP warnings or database related errors are on the whole easy to fix. The process is fairly simple:-
- Check the PHP error log
- Identify the first error (using the time log)
- Correct first error
- Recheck the PHP error log
- Rectify the next error
- Repeat
The vast majority of PHP scripts are associated with the open source content platform WordPress and the thousands upon thousands of WordPress plug-ins. You may also see an array of PHP errors when you upgrade the version of PHP on your server. Some of the older plug-ins will not always be compatible with newer versions of PHP. This can prompt a quandary, do you lose the added functionality of the new PHP version, and remove incompatible plug-ins, or do you stick with the older PHP version and favoured plug-ins?
All in all, PHP is a major plus for the programming world. Assisting website designers to create dynamic websites with amazing levels of interaction. As with the best programming languages, PHP is simple to use and the vast majority of errors are fairly easy to correct.