Re: Printing out or displaying for debugging [message #179842 is a reply to message #179836] |
Tue, 11 December 2012 17:31 |
Shake
Messages: 40 Registered: May 2012
Karma:
|
Member |
|
|
There are lots of ways.
First:
use print_r
use var_dump
Check de manual for these useful tools.
Second:
To show info in screen:
- You can check the IP-
- You can check user logged of type Admin.
- You can pass (and check) some data by GET
An usefull way is (short and simple version):
Use a function with global var (or better static), something like
function DebugInfo($text, $bWeb = true) {
global $DebugInfoTxT;
$DebugInfoTxT .= "$text\n";
if($bWeb) $DebugInfoTxT .= '<br />';
}
You can call this function to "save" debug info.
<?php
if($something) {
DebugInfo('something is true');
}
DebugInfo("Value $something");
?>
And at the end, a function that "echoes" everything:
function showDebug() {
global $DebugInfoTxT;
//check here things, like UP, User, or some get... for example
if(isset($_GET['debug'])&&$_GET['debug']=='ejd7d7ehebd') {
echo "<div id='debug'>$DebugInfoTxT</div>\n";
}
}
With some CSS, and Some Javascript, you can make the "debug" DIV easy to
see, hide...
Encapsulate this in a Class...
regards
|
|
|