note 116284 added to debugger
| From: | skatebikeratgmaildotcom | Date: | Fri, 05 Dec 2014 13:24:19 +0000 |
| Subject: | note 116284 added to debugger | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201074@lists.php.net to get a copy of this message | ||
p_r() is a function for logging variable values.
In this example the function p_r() does only log when the URL parameter d=<nonzero> is set.
Reset it by d=0.
When the parameter is a valid filename (relative to the script's path) it will be logged to
that file rather than to the browser.
[code]
@session_start();
// debug
if (isset($_GET['d']))
{
$_SESSION['d'] = $_GET['d'];
}
if (@$_SESSION['d']) {
function p_r($exp)
{
$res = "";
$trace = debug_backtrace();
$level = 0;
$e = error_reporting(E_ALL&~E_NOTICE);
$file = strrpos($trace[$level]['file'], "/");
$file = substr($trace[$level]['file'],$file+1);
$line = date("H:i:s"). " " . $file . ' ' .
$trace[$level]['line'] . ' ' . $trace[$level+1]['function'] .
"()";
$e = error_reporting($e);
if (!is_string($exp)) $exp = var_export($exp,1);
if (substr($_SESSION["d"],-4)==".log") {
file_put_contents ($_SESSION["d"],$line . ": ". $exp . "\n",
FILE_APPEND);
} else {
$res = $line . "\n<pre>".htmlentities($exp). "</pre>\n";
echo $res;
}
return $res;
}
// refresh to prevent timeout
$a = $_SESSION['d'];
$_SESSION['d'] = $a;
error_reporting (E_ALL);
} else {
function p_r() {}
} // end if debug
[/code]
----
Server IP: 72.52.91.14
Probable Submitter: 46.165.210.17
----
Manual Page -- http://php.net/manual/en/debugger.php
Edit -- https://master.php.net/note/edit/116284
Del: integrated -- https://master.php.net/note/delete/116284/integrated
Del: useless -- https://master.php.net/note/delete/116284/useless
Del: bad code -- https://master.php.net/note/delete/116284/bad+code
Del: spam -- https://master.php.net/note/delete/116284/spam
Del: non-english -- https://master.php.net/note/delete/116284/non-english
Del: in docs -- https://master.php.net/note/delete/116284/in+docs
Del: other reasons-- https://master.php.net/note/delete/116284
Reject -- https://master.php.net/note/reject/116284
Search -- https://master.php.net/manage/user-notes.php