How to pass GET and POST data to the php executable?

余生颓废 提交于 2019-11-30 21:20:27

For GET: The Easy Way (That i've found):

php-cgi.exe <script-file-name> <parameter1>=<value1> <parameter2>=<value2> [...] <parameterN>=<valueN>

The Harder Way (via php-cgi and windows cli) would be:

SET "QUERY_STRING=<parameter1>=<value1>&<parameter2>=<value2>&[...]&<paramterN>=<valueN>"
SET SCRIPT_NAME=<script-file-name>
SET REQUEST_METHOD=GET
SET REDIRECT_STATUS=0
php-cgi.exe

I'd assume there would be a way to set environment variable via C#/.Net. The environment variables would have to be unset after php-cgi.exe completes.

More info for CGI environment variables you could set (and CGI in general) at http://www.ietf.org/rfc/rfc3875.txt. Might also be of use would be PHP's $_SERVER variable documentation. Security considerations for running PHP as CGI also in PHP documentation at php.net.

Are you familiar with CGI? This is normally how web servers will execute arbitrary external programs.

There are certainly more modern alternatives to CGI, but (almost) every web server and external program today will support CGI.

If you're in bash or a similar shell, try this: QUERY_STRING="fruitKind=apple&basketId=1000" php -q foo.php.

Have you considered piping the GET/POST data as STDIN to the PHP executable? i.e.

system("echo ".GETOrPOSTData." > foobar.php");

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!