views:

67

answers:

1

Hello friends.

We have an application running on IIS 6 which uses a custom HttpModule to rewrite urls. This works great (well done us) except in the case where the Context.RewritePath destination is a .php file. The php file is executed as expected, however the $_POST collection is empty meaning it cannot access any forms which are submitted to rewritten urls. The problem does not exist when rewriting to .aspx files as the Request.Form collection is fine.

My question therefore has two parts: Why is the $_POST collection not being populated? Is there a way to ensure that the .php $_POST collection is correctly populated after a rewrite?

I don't have much to show in the way of code. There's just a simple:

context.RewritePath(newPath);

once the HttpModule has figured out where to send the request.

Edit: Interestingly, if I do var_dump(file_get_contents('php://input')); in the PHP file (method described here) the contents of the form is displayed. So the data is reaching the PHP script but not the $_POST array.

+1  A: 

Redirecting turns a POST action into a GET action, which means that any POST parameters initially sent are lost. You'll have to use a backchannel method (e.g. sessions) in order to pass the variables along.

Ignacio Vazquez-Abrams
Thanks for your incredibly quick answer. How is it that .aspx pages can access the form collection but .php files can't?
jammus
My guess is that ASP.NET implements the backchannel transparently.
Ignacio Vazquez-Abrams
Good old ASP.NET. Interesting a call to file_get_contents('php://input') shows that the POST data is getting through somehow. Just that the $_POST array isn't getting populated.
jammus
What does `$_SERVER["REQUEST_METHOD"]` give? If it's not `POST` then it probably won't try to grab the parameters.
Ignacio Vazquez-Abrams
Yeah, as you suggested above it's marked as a GET. I've found a work around but sadly it doesn't work when the form includes a file upload which some of ours do. Ho-hum. Again, thanks loads for your time and attention with this one.
jammus