I have a very simple CGI webserver running using python CGIHTTPServer class. This class spawns and executes a cgi-php script. If the webpage sends POST request, how can I access the POST request data in the php script?
1 Answer
When you say your Python process "spawns and executes" a cgi-php script, I believe what you mean is "it calls my PHP script by executing the PHP CLI executable, passing it the name of my script."
Using the PHP CLI executable, HTTP-specific superglobals and environment values will not be set automatically. You would have to read in all HTTP request headers and GET/POST data in your Python server process, and then set them in the environment used by your PHP script.
The whole experiment sounds interesting, but this is what mod_php does already.
2 Comments
Methos
Yes you are quite right and I did not clarify in my question. I know that I'll have to set the POST data in global variables for the cgi script. However, my problem is I don't know which routine receives that data in the python CGIHTTPServer. There is a run_cgi() routine that listens for additional data. However that data is discarded. So I am confused.
AJ.
Have a look at the
BaseHTTPServer class...it's an ancestor class of CGIHTTPServer. Here's the reference: docs.python.org/library/…