0

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?

Methos
  • 13,608
  • 11
  • 46
  • 49

1 Answers1

1

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.

AJ.
  • 27,586
  • 18
  • 84
  • 94
  • 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. – Methos Jul 15 '11 at 22:15
  • 1
    Have a look at the `BaseHTTPServer` class...it's an ancestor class of `CGIHTTPServer`. Here's the reference: http://docs.python.org/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler – AJ. Jul 16 '11 at 00:36