PHP.exe interpreter and sending variables

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

    PHP.exe interpreter and sending variables

    Question, I am testing php scripts through the console app(php.exe) how
    can I send form variables to it? Or can I? Can I just fill in
    variables into _POST['val'] for example.

    --
    Ramza from Atlanta

  • Alvaro G Vicario

    #2
    Re: PHP.exe interpreter and sending variables

    *** Ramza Brown wrote/escribió (Thu, 11 Aug 2005 08:04:21 -0400):[color=blue]
    > Question, I am testing php scripts through the console app(php.exe) how
    > can I send form variables to it? Or can I? Can I just fill in
    > variables into _POST['val'] for example.[/color]

    POST is a method of the HTTP protocol, protocol that is obviously not used
    when executing a script though the command line. If your input comes from
    forms, you should probably write an intermediate script that runs through a
    web server and convert the input in something a command line tool can reach
    (database, file, command-line arguments...).

    Yes, $_POST is a writeable array but, where are you getting the values to
    fill into it?

    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    • ZeldorBlat

      #3
      Re: PHP.exe interpreter and sending variables

      Check out $argc[] and $argv[]:



      Comment

      • Ramza Brown

        #4
        Re: PHP.exe interpreter and sending variables

        ZeldorBlat wrote:[color=blue]
        > Check out $argc[] and $argv[]:
        >
        > http://www.php.net/reserved.variables
        >[/color]
        Hmm, this looks interesting, can you translate that? For what I want.

        --
        Ramza from Atlanta

        Comment

        • ZeldorBlat

          #5
          Re: PHP.exe interpreter and sending variables

          One option would be to pass each desired form variable as a key=value
          pair, then have a method populate $_POST from $argv. So, if you had
          three post variables called var1, var2, and var3, you would call your
          script from the command line as follows:

          php myscript.php var1=val1 var2=val2 var3=val3

          Then, inside your script, do something like this:

          for($i = 1; $i < $argc; $i++) { //the first one is the script name
          $param = explode('=', $argv[$i]);
          $_POST[$param[0]] = $params[1];
          }

          Another alternative would be to pass a single command line argument
          containing something like a URL query string. So, in the above example
          you would use the following on the command line:

          php myscript.php var1=val1&var2= val2&var3=val3

          Then, inside your script, try something like:

          $params = array();
          parse_str($argv[1], $params);
          foreach($params as $key => $val)
          $_POST[$key] = $val;

          Comment

          • Ramza Brown

            #6
            Re: PHP.exe interpreter and sending variables

            ZeldorBlat wrote:[color=blue]
            > One option would be to pass each desired form variable as a key=value
            > pair, then have a method populate $_POST from $argv. So, if you had
            > three post variables called var1, var2, and var3, you would call your
            > script from the command line as follows:
            >
            > php myscript.php var1=val1 var2=val2 var3=val3
            >
            > Then, inside your script, do something like this:
            >
            > for($i = 1; $i < $argc; $i++) { //the first one is the script name
            > $param = explode('=', $argv[$i]);
            > $_POST[$param[0]] = $params[1];
            > }
            >
            > Another alternative would be to pass a single command line argument
            > containing something like a URL query string. So, in the above example
            > you would use the following on the command line:
            >
            > php myscript.php var1=val1&var2= val2&var3=val3
            >
            > Then, inside your script, try something like:
            >
            > $params = array();
            > parse_str($argv[1], $params);
            > foreach($params as $key => $val)
            > $_POST[$key] = $val;
            >[/color]
            Gracias, thanks.


            --
            Ramza from Atlanta

            Comment

            Working...