[PHP] Simple function to help with debugging

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

@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