Skip to content

Instantly share code, notes, and snippets.

@nfreear
Created January 31, 2012 17:15
Show Gist options
  • Save nfreear/1711664 to your computer and use it in GitHub Desktop.
Save nfreear/1711664 to your computer and use it in GitHub Desktop.
Output a PHP string or expression as a HTTP header / Drupal
<?php
/**If a 'debug' parameter is set, output a PHP string or expression, probably as a HTTP header.
*
* Inspired by OUVLE ouauth module, and FirePHP.
*
* @param mixed $exp A PHP string or expression.
* @copyright 2012-01-31 N.D.Freear.
*/
function _MY_DRUPAL_MODULE_debug($exp) {
// For Drupal, try variable_get().
if ((isset($_GET['debug']) && $_GET['debug']) || variable_get('debug', NULL)) {
static $count = 0;
static $where;
// $where could be based on __FUNCTION__ or debug_backtrace().
if(!$where)$where = str_replace(array('_','.'), '-', basename(__FILE__));
@header("X-D-$where-$count: ".json_encode($exp));
$count++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment