Debugging $_GET for debugging on a LIVE server

The following bit of php code will can help you quickly debug something on LIVE or core without outputting stuff to everyone. It also throws no notices if no $_GET is present. Appending ?debug=debug to the URL will cause it to engage.

<?php
 
if (!empty($_GET) && !empty($_GET["debug"]) && ($_GET["debug"] == 'debug' ))
{
  echo
'something useful';
}
?>

A Drupal specific one if you want to further ensure that it only works if logged in as admin

<?php
 
global $user;
if ((
$user->uid === '1') && !empty($_GET) && !empty($_GET["debug"]) && ($_GET["debug"] == 'debug' ))
{
  echo
'something useful more SECURELY';
}
?>

Custom debug function for a module

When builiding a module, it is helpful to put in a custom debug function that you can call from various places within the module. I recommend something like this:
Change "module_name to match your module" and change "debugTrigger" to match the item in the $_GET that you want the debug to trigger upon ('video', 'data', 'blocks' ...)

<?php
 
function module_name_debug ($mThing='', $sMessage = ''){
    if (!empty(
$_GET) && !empty($_GET["debug"]) && ($_GET["debug"] == 'debugTrigger' )) {
     
kpr(" ---------------- $sMessage ------------ ");
     
kpr($mThing);
    }
}
?>

Then simply call the function in your code at any point in time that you want debug info output. Give it the var you want to output and the message you want to describe what is being output:

<?php
 module_name_debug
($aVideoInfo, '$aVideoInfo being passed to the build video function.' );
?>

After you create a custom debug trigger, be sure to add it to the module help output so people know it is there..

section: