How to Create Error Messages like Codeigniter, Drupal and Custom type with PHP

Creating Custom Error Messages using PHP is pretty simple. While running PHP scripts if you encounter any errors like Fatal error, NoticeĀ  and Warnings, PHP will throw the Error to Browser with Default Error Message. Those errors will not have and user experience when some pages in your web page struck with error. That’s why CodeIgniter, Drupal and many other framework have their own error reporting style. So the script attached with this post allows you to modify your application error with some style or effects associated with the theme of your project.

The attached script contains three files namely codeigniter , drupal and custom PHP. You can easily embed this code/class with any of your PHP applications. Even with any frameworks. set_error_handler(“error_handler”, E_ALL); – this inbuilt PHP function will say the PHP to accept which error handling method. If you didn’t specify this inbuilt function the PHP will through default error message. You can use your own PHP function to attract the user by giving some proper error messages like “Something, went wrong our team is checking and fix this issues…”

The attached folder consists of 4 files,

  1. codeigniterexceptions.php
  2. customexceptions.php
  3. drupalexceptions.php
  4. example.php

Steps to install this PHP script in your application.

Step1 : Include any one of these files(codeigniterexceptions.php, customexceptions.php and drupalexceptions.php) in your config file at the bottom of the page.

Step2 : Run your application, if you find any error the script will convert default error message into some custom error message which u choose and displayed.

You can check the demo for more understanding.

Requirement:- PHP
Demo : –