Selectively turning on debug mode

Debug mode is a very helpful tool when developing your site. However, it becomes an issue when you want to turn debug mode on when your site is live. You can turn it on, check the output, and turn it off again before anyone notices, but there is the chance that someone will stumble on your debug data, especially if it is a popular site. It is also a security issue, due to paths, SQL commands and module lists giving hackers a place to start. This tutorial will show you how to turn debug mode on, but so that only you can see the output.

In your config.php file, replace the following line:

$config['debug'] = false;

with:

if ($_GET['debug'] && $_SESSION['cms_admin_username']) {
  $config['debug'] = true;
} else {
  $config['debug'] = false;
}

You can access debug mode by adding ?debug=1 to your URL in the browser address bar. If you already have options, append &debug=1 . This will only work if you have logged into the admin panel in the same session.

Even if someone stumbles on the ?debug=true trick, they won't see anything, because they haven't logged in.

Comments