Printing out or displaying for debugging [message #179836] |
Tue, 11 December 2012 15:59  |
C
Messages: 24 Registered: January 2012
Karma: 0
|
Junior Member |
|
|
What is a good way to see the values of a few variables for debugging?
I cannot debug locally. I have to put the code on the server in the
normal Internet site (which does not receive a lot of human visitors),
so it would not hurt to display the values of some variables for a few
minutes while I am debugging.
|
|
|
|
|
Re: Printing out or displaying for debugging [message #179840 is a reply to message #179837] |
Tue, 11 December 2012 16:59   |
C
Messages: 24 Registered: January 2012
Karma: 0
|
Junior Member |
|
|
I am just a beginner, so I will need help with the actual commands I should use, not necessarily the whole code, but the commands which I should learn to use. Thanks.
On Tuesday, December 11, 2012 6:05:19 PM UTC+2, The Natural Philosopher wrote:
> On 11/12/12 15:59, C wrote:
>
>> What is a good way to see the values of a few variables for debugging?
>
>> I cannot debug locally. I have to put the code on the server in the
>
>> normal Internet site (which does not receive a lot of human visitors),
>
>> so it would not hurt to display the values of some variables for a few
>
>> minutes while I am debugging.
>
>>
>
> I would write a php function that does three things.
>
> (i) checks to see if the browser remote IP address is you, and if it
>
> isn't, does nothing - that lets all of your other users off the hook.
>
> (ii) adds any error and debugging messages to a big chunk of memory.
>
> (iii) RIGHT at the end of you page, calls the function again to
>
> *display* the buffer contents in a <div> that overlays everything.
>
>
>
> An alternative is to create a debug notice area in some empty bit of
>
> real estate.
>
>
>
>
>
>
>
> --
>
> Ineptocracy
>
>
>
> (in-ep-toc’-ra-cy) – a system of government where the least capable to
>
> lead are elected by the least capable of producing, and where the
>
> members of society least likely to sustain themselves or succeed, are
>
> rewarded with goods and services paid for by the confiscated wealth of a
>
> diminishing number of producers.
|
|
|
|
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: 0
|
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
|
|
|
|
|
|
|
|
|
|
|
Re: Printing out or displaying for debugging [message #179864 is a reply to message #179846] |
Thu, 13 December 2012 13:29  |
C
Messages: 24 Registered: January 2012
Karma: 0
|
Junior Member |
|
|
On Tuesday, December 11, 2012 9:04:28 PM UTC+2, Robert Heller wrote:
> At Tue, 11 Dec 2012 07:59:47 -0800 (PST) C <wrong(dot)address(dot)1(at)gmail(dot)com> wrote: > > What is a good way to see the values of a few variables for debugging? > I cannot debug locally. I have to put the code on the server in the > normal Internet site (which does not receive a lot of human visitors), > so it would not hurt to display the values of some variables for a few > minutes while I am debugging. echo '<!-- var1 = '.$var1.' -->'; This creates an HTML comment. Nothing is actually displayed in your (or anyone else's) browser. BUT if you <right click>=>Show Page Source, you can see the HTML code, including the HTML comments. > -- Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com Deepwoods Software -- http://www.deepsoft.com/ () ascii ribbon campaign -- against html e-mail /\ www.asciiribbon.org -- against proprietary attachments
I think this was the best way. I did this and found the error with little effort. Thanks very much.
|
|
|