FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Printing out or displaying for debugging
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Printing out or displaying for debugging [message #179836] Tue, 11 December 2012 15:59 Go to next message
C is currently offline  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 #179837 is a reply to message #179836] Tue, 11 December 2012 16:05 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
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 #179838 is a reply to message #179836] Tue, 11 December 2012 16:24 Go to previous messageGo to next message
Salvatore is currently offline  Salvatore
Messages: 38
Registered: September 2012
Karma: 0
Member
On 2012-12-11, 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?

var_export() works great as long as you set the second parameter to
true.

--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
Re: Printing out or displaying for debugging [message #179840 is a reply to message #179837] Tue, 11 December 2012 16:59 Go to previous messageGo to next message
C is currently offline  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 #179841 is a reply to message #179836] Tue, 11 December 2012 17:16 Go to previous messageGo to next message
Martin Leese is currently offline  Martin Leese
Messages: 23
Registered: June 2012
Karma: 0
Junior Member
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.

What I typically do is make a copy of the
webpage and call it TestSomething.php. You
can then do whatever you want with the
knowledge that nobody else will visit the
page.

You can then display variables using:
<?php echo $a_variable; ?>

--
Regards,
Martin Leese
E-mail: please(at)see(dot)Web(dot)for(dot)e-mail(dot)INVALID
Web: http://members.tripod.com/martin_leese/
Re: Printing out or displaying for debugging [message #179842 is a reply to message #179836] Tue, 11 December 2012 17:31 Go to previous messageGo to next message
Shake is currently offline  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 #179843 is a reply to message #179836] Tue, 11 December 2012 17:32 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/11/2012 10:59 AM, 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.
>

You should ALWAYS have a development environment separate from (but very
similar to) your live system. NEVER upload untested/undebugged code to
a live system, no matter how few visitors it gets!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Printing out or displaying for debugging [message #179844 is a reply to message #179836] Tue, 11 December 2012 17:52 Go to previous messageGo to next message
Martin Leese is currently offline  Martin Leese
Messages: 23
Registered: June 2012
Karma: 0
Junior Member
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
....

I debug locally using the PHP Command Line
Interpreter (CLI). In a Windows BAT file, I
use:
php -n -f "%inputFile%" > "%outputFile%"

--
Regards,
Martin Leese
E-mail: please(at)see(dot)Web(dot)for(dot)e-mail(dot)INVALID
Web: http://members.tripod.com/martin_leese/
Re: Printing out or displaying for debugging [message #179845 is a reply to message #179841] Tue, 11 December 2012 18:18 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 11/12/12 17:16, Martin Leese wrote:
> 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.
>
> What I typically do is make a copy of the
> webpage and call it TestSomething.php. You
> can then do whatever you want with the
> knowledge that nobody else will visit the
> page.
>
> You can then display variables using:
> <?php echo $a_variable; ?>
>
sound advice.



--
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 #179846 is a reply to message #179836] Tue, 11 December 2012 19:04 Go to previous messageGo to next message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma: 0
Member
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
Re: Printing out or displaying for debugging [message #179847 is a reply to message #179843] Tue, 11 December 2012 19:04 Go to previous messageGo to next message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma: 0
Member
At Tue, 11 Dec 2012 12:32:23 -0500 Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:

>
> On 12/11/2012 10:59 AM, 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.
>>
>
> You should ALWAYS have a development environment separate from (but very
> similar to) your live system. NEVER upload untested/undebugged code to
> a live system, no matter how few visitors it gets!
>

+1

It is dead trivial to install a basic simple LAMP server either on a
random spare PC, hard drive partition, or (if your machine is new
enough) on a bootable thumb drive. Or you can install a VM system
(like VirtualBox) and install a LAMP server as a virtual machine.

(It is also possible to install a WAMP server if you really must.)

--
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
Re: Printing out or displaying for debugging [message #179848 is a reply to message #179840] Tue, 11 December 2012 20:39 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Tue, 11 Dec 2012 08:59:32 -0800, wrong.address.1 wrote:

> I am just a beginner

Indeed you are.

Lesson 1a. In usenet, by convention and etiquette of almost 30 years
(usenet is first defined in RFC 850 dated 1983), the reply goes
underneath the quoted text, not above it.

Lesson 1b. This is actually a usenet newsgroup, regardless of the form
and mechanisms by which it is presented to you. Please respect usenet
convention and etiquette here.

Rgds

Denis McMahon
Re: Printing out or displaying for debugging [message #179849 is a reply to message #179836] Wed, 12 December 2012 00:14 Go to previous messageGo to next message
SwissCheese is currently offline  SwissCheese
Messages: 17
Registered: December 2012
Karma: 0
Junior Member
On 12/11/2012 10:59 AM, 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.
>

Another method is to throw them into comments within the output HTML, ie:

echo "<!--";
vardump($var)
printr($var)
etc...
echo "-->";

then comment out/remove that code when done. Just 'View Source...' to
see it.

--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Re: Printing out or displaying for debugging [message #179850 is a reply to message #179849] Wed, 12 December 2012 06:18 Go to previous messageGo to next message
Simon is currently offline  Simon
Messages: 29
Registered: February 2011
Karma: 0
Junior Member
>
> echo "<!--";
> vardump($var)
> printr($var)
> etc...
> echo "-->";
>
> then comment out/remove that code when done. Just 'View Source...' to
> see it.

Unless $var contains html code, (maybe what the OP is trying to debug in
the first place), and that could end up causing a whole lot of mess,
(making it more difficult to debug).

A local site, is a far better option.
I prefer to install php+Apache manually but that's just a mater of choice.

Otherwise, a carbon copy of the page with the debug code on another page
is a better/safe/prettier? option.

Simon
Re: Printing out or displaying for debugging [message #179864 is a reply to message #179846] Thu, 13 December 2012 13:29 Go to previous message
C is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: When is it possible for $_SERVER['SERVER_NAME'] to contain something other than the URL which actvated the script?
Next Topic: Re: Converting file from word.doc to pdf...
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Jun 05 16:01:23 GMT 2024

Total time taken to generate the page: 0.02766 seconds