How to pass a posted variable from Bash to PHP?

Discussion in 'Programming/Scripts' started by edge, Jun 21, 2007.

  1. edge

    edge HowtoForge Supporter

    Anyone here who might know how I can pass a posted variable from Bash to a PHP script?

    When I run in Bash
    Code:
    php logit.php
    all is working fine, but when I try to add a variable like
    Code:
    php logit.php?takethis=123123
    I get an error from Bash saying that the file can not be found!

    Calling
    Code:
    php logit.php?takethis=123123
    from the website does work fine.

    The problem with Bash is the ?takethis=123123 part!

    Can the call with the ?takethis=123123 to the PHP page been done an other way in Bash?
     
    Last edited: Jun 21, 2007
  2. aqua

    aqua New Member

    i don't use php but you can try:

     
  3. falko

    falko Super Moderator

    Maybe you can add this function:

    Code:
    function getInput() {
      $fr = fopen("php://stdin", "r");
      while (!feof ($fr)) {
        $input .= fgets($fr);
      }
      fclose($fr);
      return $input;
    }
    
    $takethis = getInput();
    to your PHP script and then do something like this:

    Code:
    echo 123123 | php logit.php
    Of course, you should check the $takethis variable before you continue (to avoid that someone tries to pass harmful code to your script).
     
  4. pakogah

    pakogah New Member

    thank you very much Falko

    you save my day (or night)
     

Share This Page