Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 11th, 2004, 12:29 PM
Authorized User
 
Join Date: Jan 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Debug Stuff

Hi,

I'm writing some debug code. I want to be able to output(print) all session variables and its value, all get variables and its value and all post variables and its value (all with out knowing the variables name, so I can't use $_GET or whatever). Can anybody help me or show me some good debug code.

 
Old January 11th, 2004, 12:46 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Why wouldn't you be able to use "$_GET or whatever"? The following function var_dump, dumps out and provides information about, in this case, the arrays. You don't already have to know all possible indices in the arrays. It structures the information in a human-readable format, which is why the <pre> tags are neccessary.

http://www.php.net/var_dump
http://www.php.net/print_r is a simular function but does not provide as much information.

<?php
echo "Session variables:<br />";
    echo "<pre>";
        var_dump($_SESSION);
    echo "</pre>";
echo "Get variables:<br />";
    echo "<pre>";
        var_dump($_GET);
    echo "</pre>";
echo "Post variables:<br />";
    echo "<pre>";
        var_dump($_POST);
    echo "</pre>";

// ...etc
?>

hth,
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old January 12th, 2004, 04:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've posted this function before. It's incredibly useful:

function printr($var, $desc = '')
{
   echo "<pre>";
   if ($desc !== '') echo "{$desc}: ";
   print_r($var);
   echo "</pre>\n";
}


This lets you add an optional description to the variable you're printing out. Here are some examples:


$foo = "Some variable.";

printr($_POST, '$_POST before form processing');

if (isset($_POST['username']))
{
    $_POST['username'] = strtolower($_POST['username']);
}

printr($_POST, '$_POST after form processing');

printr($foo); // description parameter is optional.


Take care,

Nik
http://www.bigaction.org/
 
Old January 13th, 2004, 10:18 PM
Authorized User
 
Join Date: Jan 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nikolai and quesadilla5, thanks for replying! You guys are always answering questions and i appreciate that. thanks.

i was looking for something else design wise(a nice table layout) but your solutions produce the same results






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to: Have no borders and stuff! Apocolypse2005 Beginning VB 6 7 May 8th, 2007 11:56 AM
INI's and stuff! Apocolypse2005 Beginning VB 6 2 May 8th, 2007 11:38 AM
hp exam stuff ? olango Need help with your homework? 1 September 23rd, 2006 06:47 PM
Basic Stuff... Colm_L Javascript How-To 0 September 14th, 2006 08:02 AM
DAL 'stuff' pithhelmet VB Databases Basics 0 November 10th, 2004 04:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.