Passing $_POST variables to command line php

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all! I'm trying to test some php script using the command line php.exe.  
Is there any way to pass the $_POST variables? I know how to pass the $_GET  
variables, but I don't know how to do this for the $_POST ones. Thank you  


Re: Passing $_POST variables to command line php

Infiliset wrote:

Quoted text here. Click to load it

Easiest and most flexible way to do this is to include at the top of your

    $debugging = TRUE;
    $from_command_line = !strlen($_SERVER['HTTP_HOST']);

    if ($debugging && $from_command_line)
        include "test_post_vars.php";

Then populate test_post_vars.php with your $_POST variables. For example:


You may want to include various other parts of debugging code later on in
the file using "if ($debugging)" or "if ($debugging && $from_command_line)".
Never use just "if ($from_command_line)" though!


    if ($debugging)
        echo "\n<pre>\n";
        echo "\n<b>$_POST</b>\n"; var_dump($_POST);
        echo "\n<b>$_GET</b>\n"; var_dump($_GET);
        echo "\n<b>$_COOKIE</b>\n"; var_dump($_COOKIE);
        echo "\n<b>$_SERVER</b>\n"; var_dump($_SERVER);
        echo "\n<b>$_SESSION</b>\n"; var_dump($_SESSION);
        echo "\n</pre>\n";

at the end of your code can be useful.

When finished debugging, just set $debugging=FALSE.

Toby A Inkster BSc (Hons) ARCS
Contact Me  ~

Site Timeline