SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile debug script for you :)

    Hi Sitepoint users,

    I found a crappie debug script in one of my php books. I could see its potential so I played with it and well... made it better : P I thought to myself what better place to share it. I have found it so far to be very useful.

    Ok well you can use it how ever you want. My suggestion to include it at the bottom of your script.

    It works with put action=debug1 or action=debug2 along the url pram

    Eg.
    Code:
    www.testsite.com/page.php?action=debug1
    (yep I know you get, just there for the new peeps)


    Ok well in debug mode 1 the dump is at the bottom of the page in HTML and in mode2 the dump in bottom of the source page in html comments.

    hope this helps

    Ps. if you don't like it don't flame me, just move on and if you do like and want to improve it please post the updated version in this thread for me and others to see.

    ##note sorry for using code tags and not php code tags, the dam thing wouldn't work

    Code:
     
    <? 
    /*
    #######DEBUG######### 
    */
     
    //fucntion used to dump vars
    function dump_array($array)
    {
    if(is_array($array))
    {
    	$size = count($array);
    	$string = "";
    	if($size)
    	{
    	 $count = 0;
    	 $string .= "{ ";
    	 // add each element's key and value to the string
    	 foreach($array as $var => $value)
    	 {
    		$string .= "$var = '$value'";
    		if($count++ < ($size-1)) 
    		{
    		 if ($_GET['action'] == 'debug1')
    		 {
    			$string .= ",\n<br>\n< ";
    		 } else {
    			$string .= ",\n";
    		 }
    		}
    	 }
    	 $string .= " }";
    	}
    	return $string;
    }
    else 
    {
    	// if it is not an array, just return it
    	return $array;
    }
    }
     
    //var dump
     
    if ($_GET['action'] == 'debug1') 
    {
      echo "\n<br>\n<h2>BEGIN VARIABLE DUMP<h2>\n<br>\n";
      echo "<br>\n<h4>BEGIN GET VARS<h4>\n<br>\n";
      
      echo dump_array($HTTP_GET_VARS);
      echo "<br>\n<h4>BEGIN POST VARS<h4>\n<br>\n";
      
      echo dump_array($HTTP_POST_VARS);
      echo "<br>\n<h4>BEGIN SESSION VARS<h4>\n<br>\n";
      
      echo dump_array($HTTP_SESSION_VARS);
      echo "<br>\n<h4>BEGIN COOKIE VARS<h4>\n<br>\n";
      
      echo dump_array($HTTP_COOKIE_VARS);
    
      echo "\n<br>\n<h2>END VARIABLE DUMP<h2>";
    } 
    elseif ($_GET['action'] == 'debug2') 
    {
      echo "\n<!-- ********* BEGIN VARIABLE DUMP ********** -->\n\n";
    
      echo "\n<!-- ## BEGIN GET VARS ## -->\n";
      echo "\n<!-- \n".dump_array($HTTP_GET_VARS)."\n -->\n";
     
      echo "\n<!-- ## BEGIN POST VARS ## -->\n";
      echo "\n<!-- \n".dump_array($HTTP_POST_VARS)."\n-->\n";
     
      echo "\n<!-- ## BEGIN SESSION VARS ## -->\n";
      echo "\n<!-- \n".dump_array($HTTP_SESSION_VARS)."\n -->\n";
     
      echo "\n<!-- ## BEGIN COOKIE VARS ## -->\n";
      echo "\n<!-- \n".dump_array($HTTP_COOKIE_VARS)."\n -->\n";
    
      echo "\n<!-- ********* END VARIABLE DUMP ********** -->\n";
    } 
    else 
    {
      return; 
    }
    ?>
    Last edited by Mower; Apr 25, 2004 at 20:06. Reason: arrrrrrrrrhhhhhhhh problems with displaying the code


    "Will I ever find my way to GURU?"

  2. #2
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so no one likes it ...... oh well


    "Will I ever find my way to GURU?"

  3. #3
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh, I will give it a try, just 'cause I don't like when people cry

    thanks for sharing.

  4. #4
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YAY!!!

    I loved it, and I hope you do too.


    "Will I ever find my way to GURU?"

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is an interesting idea.. i'll play with it when i have time and will post it then.. i think it will be great if some of more experienced PHP users post their ideas too.. there are some debuggers but i still don't use anyone of them.. can someone point me to the best one? maybe someone will post thoughts if such kind of debugging script is needed when using debugger, will be easier to display debugging information with it, etc.. if anyone have some thoughts and experience with debugging in PHP and wants to share them with others..

  6. #6
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes I would like to know about other out there too. I am about to start writing a massive php driven site JOY!! and was looking at building error, debug, testing code into to site code. I have been testing a few differnt ideas.

    Here is what I have come up with. I am going to write a debug class, error reporting class (yes i know there are heaps) and a testing class.

    The testing class is going to be the hardest, and as yet I haven't got a good idea of how to go about it.

    The debug class is going to be easy and will be posted when I have finshed it. Oh and it will not be like this LOL but a more complex system.... If i can pull it off with out blowing our the code.


    "Will I ever find my way to GURU?"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •