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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Have a look at the BaseHTTPServer class...it's an ancestor class of CGIHTTPServer. Here's the reference: docs.python.org/library/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.