# \[PHP\] Simple function to help with debugging

**URL:** <https://forum.kirupa.com/t/php-simple-function-to-help-with-debugging/251390>\
**Category:** programming\
**Created:** [February 7, 2008, 10:52pm UTC](https://forum.kirupa.com/t/php-simple-function-to-help-with-debugging/251390 "2008-02-07T22:52:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarkAz](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@DarkAz](https://forum.kirupa.com/u/DarkAz)\
**Post date:** [February 7, 2008, 10:52pm UTC](https://forum.kirupa.com/t/php-simple-function-to-help-with-debugging/251390/1 "2008-02-07T22:52:39Z")

</div>

It seems that a lot of the PHP-related problems posted on this forum are easily fixed with some simple environment/global variable analysis

here’s a simple routine that you can add to your code to display these and make things a bit easier

note you will need to ensure your script calls session\_start() before the debugInfo() function if you want to view the current session variables

```php
<?php

@session_start();

function debugInfo() {
    // echo out the optional variables
    if (count($_POST)) {
        echo "<h1>POST Variables</h1>
";
        echo "<pre>" . print_r($_POST, true) . "</pre>
";
    }
    if (count($_GET)) {
        echo "<h1>GET Variables</h1>
";
        echo "<pre>" . print_r($_GET, true) . "</pre>
";
    }
    if (count($_SESSION)) {
        echo "<h1>SESSION Variables</h1>
";
        echo "<pre>" . print_r($_SESSION, true) . "</pre>
";
    }
    if (count($_COOKIE)) {
        echo "<h1>COOKIE Variables</h1>
";
        echo "<pre>" . print_r($_COOKIE, true) . "</pre>
";
    }
    if (count($_REQUEST)) {
        echo "<h1>REQUEST Variables</h1>
";
        echo "<pre>" . print_r($_REQUEST, true) . "</pre>
";
    }
    
    // echo out the server variables (always exist)
    echo "<h1>SERVER Variables</h1>
";
    echo "<pre>" . print_r($_SERVER, true) . "</pre>
";
}

?>

```

Hopefully this will be of some use
