Home > PHP > Controlling Error Reporting On Different Servers With PHP

Controlling Error Reporting On Different Servers With PHP

Having a testing server is quite a common practice, but what happens when you want to go live and you don’t want all of your error messages displayed?

A good way of doing this is to create a variable that you can then use to detect what server your code is running on and set your error displaying accordingly. The following section of code will set a variable to true if the code is not running on the server name www.talkincode.com. This variable is then used to set the error reporting level.

<?php
 $turnOnErrors = $_SERVER['SERVER_NAME'] != 'www.talkincode.com';
 
 if($turnOnErrors){
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
 }else{
  error_reporting(0);
  ini_set('display_errors', 0);
 }
?>

Information, services, and products:
If your looking for the prefect Wedding dress come to us.
Oak furniture
Office Furniture
brays furniture
Shabby Chic Furniture available here
Categories: PHP Tags: , , , , ,
  1. No comments yet.
  1. No trackbacks yet.