calling exec on a php file and passing parameters?

前端 未结 5 1701
慢半拍i
慢半拍i 2021-02-19 00:53

I am wanting to call a php file using exec.

When I call it I want to be able to pass a variable through (an id).

I can call echo exec(\"php /var/www/unity/

5条回答
  •  广开言路
    2021-02-19 00:59

    Your call is failing because you're using a web-style syntax (?parameter=value) with a command-line invokation. I understand what you're thinking, but it simply doesn't work.

    You'll want to use $argv instead. See the PHP manual.

    To see this in action, write this one-liner to a file:

    
    

    Then invoke it from the command-line with arguments:

    php -f /path/to/the/file.php firstparam secondparam
    

    You'll see that $argv contains the name of the script itself as element zero, followed by whatever other parameters you passed in.

提交回复
热议问题