Passing $_POST variables to command line php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Infiliset

    Passing $_POST variables to command line php

    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
    all!


    Matthew


  • Toby Inkster

    #2
    Re: Passing $_POST variables to command line php

    Infiliset wrote:
    [color=blue]
    > 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
    > all![/color]

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

    <?php
    $debugging = TRUE;
    $from_command_l ine = !strlen($_SERVE R['HTTP_HOST']);

    if ($debugging && $from_command_l ine)
    include "test_post_vars .php";
    ?>

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

    <?php
    $_POST['username']='henry';
    $_POST['password']='secret';
    ?>

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

    e.g.

    <?php
    if ($debugging)
    {
    echo "\n<pre>\n" ;
    echo "\n<b>\$_PO ST</b>\n"; var_dump($_POST );
    echo "\n<b>\$_GE T</b>\n"; var_dump($_GET) ;
    echo "\n<b>\$_COOKIE </b>\n"; var_dump($_COOK IE);
    echo "\n<b>\$_SERVER </b>\n"; var_dump($_SERV ER);
    echo "\n<b>\$_SESSIO N</b>\n"; var_dump($_SESS ION);
    echo "\n</pre>\n";
    }
    ?>

    at the end of your code can be useful.

    When finished debugging, just set $debugging=FALS E.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact

    Comment

    Working...