Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am writing a web server in C# and I'm trying to add support for PHP. I have it mostly working, except I don't know how to past GET and POST data to the PHP executable when i pass the file to it. I've been testing with GET since I haven't gotten to getting POST requests handled on the server, and I have the string of the arguments that gets passed separated, but I don't know how to feed the information to the php parser. Some tips would be appreciated.

like image 307
The.Anti.9 Avatar asked Jun 03 '09 03:06

The.Anti.9


3 Answers

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.

like image 51
Vin-G Avatar answered Nov 12 '22 05:11

Vin-G


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.

like image 36
Greg Hewgill Avatar answered Nov 12 '22 05:11

Greg Hewgill


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

like image 1
John Feminella Avatar answered Nov 12 '22 07:11

John Feminella