Quick Debugging Function

Sometimes it helps to have a variable checking function that simply spits out what values are contained in your variables. If you run into undefined errors (even object errors) its a good idea to check your variables and make sure your passing the correct values. Here’s a quick function to output most of your main sources of information. It’s handy to call this function before the lines that are causing the error but as close to the error cause as possible.

function check_vars() {
	echo "COOKIE variables: n<pre>";
    print_r($_COOKIE);

	echo "</pre><br />SESSION variables: n<pre>" ;
    print_r($_SESSION);

	echo "</pre><br />GET variables: n<pre>";
    print_r($_GET);

	echo "</pre><br />POST variables: n<pre>" ;
    print_r($_POST);

    echo "</pre><br />SERVER variables: n<pre>" ;
    print_r($_SERVER);
	echo "</pre>";
}

Simply include this function and call it immediately before your errors and you should see what’s available in your scripts!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.