calling exec on a php file and passing parameters?

前端 未结 5 1699
慢半拍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:55

    If you want to pass a GET parameter to it, then it's mandatory to provide a php-cgi binary for invocation:

    exec("QUERY_STRING=id=123 php-cgi /var/www/emailer.php");
    

    But this might require more fake CGI environment variables. Hencewhy it is often advisable to rewrite the called script and let it take normal commandline arguments and read them via $_SERVER["argv"].

    (You could likewise just fake the php-cgi behaviour with a normal php interpreter and above example by adding parse_str($_SERVER["QUERY_STRING"], $_GET); on top of your script.)

提交回复
热议问题