Skip to content

Instantly share code, notes, and snippets.

@littlefuntik
Created October 28, 2015 09:29
Show Gist options
  • Save littlefuntik/94e3eb9a4dcc6c0205e5 to your computer and use it in GitHub Desktop.
Save littlefuntik/94e3eb9a4dcc6c0205e5 to your computer and use it in GitHub Desktop.
Debug info in position absolute in page by condition
<?php
if(!defined('MICROTIME_START')) { define('MICROTIME_START', microtime(true)); }
if(!function_exists('mytrace')) {function mytrace () { static $cnt=0, $h=20; $diff=round(microtime(true)-MICROTIME_START,3); if(isset($_COOKIE['EC']) && 'Y' === $_COOKIE['EC']) {
$trace = reset(debug_backtrace()); $style='text-shadow: 0px 1px 0 #b0b0b0;border-bottom:1px solid lightgray;padding:3px;font-size:12px;font-family:arial;background:rgba(255,255,255,.8);position:absolute;left:0;top:'.(140+$cnt*$h).'px;z-index:9999;height:'.$h.'px;width:100%;box-sizing:border-box;';
echo PHP_EOL.'<pre style="'.$style.'">[TRACE] ('.$diff.'s) '.$trace['file'].':'.$trace['line'].'</pre>'.PHP_EOL;
++$cnt;
}}}
if(!function_exists('mydie')) {function mydie () { if(isset($_COOKIE['EC']) && 'Y' === $_COOKIE['EC']) die; }}
// P.S. COOKIE "EC" must be set value "Y"
// use:
// mytrace();
// .. some code
// mytrace();
// .. some code
// mytrace(); mydie();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment