Skip to content

Instantly share code, notes, and snippets.

@Exadra37
Last active August 29, 2015 14:12
Show Gist options
  • Save Exadra37/f7a31181189e0d5ec69f to your computer and use it in GitHub Desktop.
Save Exadra37/f7a31181189e0d5ec69f to your computer and use it in GitHub Desktop.
Debug On Screen, restricted by Ip Address, several vars at once, using var_dump() or print_r()
<?php
/**
* @author Exadra37 <exadra37atgmailpointcom>
* @since 2014/01/03
*/
if (!function_exists('debugOnScreen')) {
function debugOnScreen(array $vars, $print_r = false, $die = false)
{
$remote_ip_address = $_SERVER['REMOTE_ADDR'];
$dev_ip_address = array('123.45.67.89'); // allowed ip addresses
if (in_array($remote_ip_address, $dev_ip_address)) {
foreach ($vars as $key => $var) {
$var_name = (is_int($key)) ? 'Undefined Var Name' : $key;
echo "<hr>{$var_name}<pre>";
if ($print_r) {
print_r($var)
} else {
var_dump($var);
}
echo "</pre><hr>";
}
if ($die) {
die();
}
return true;
}
return false;
}
}
if (!function_exists('prvars')) {
function prvars(array $vars) {
debugOnScreen($vars, true, false);
}
}
if (!function_exists('vdvars')) {
function vdvars(array $vars) {
debugOnScreen($vars, false, false);
}
}
if (!function_exists('dprvars')) {
function dprvars(array $vars) {
debugOnScreen($vars, true, true);
}
}
if (!function_exists('dvdvars')) {
function dvdvars(array $vars) {
debugOnScreen($vars, false, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment