473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Problem getting POST body in PHP

So here's the situation: I need to write a PHP script which accepts form submissions using all methods (GET and POST) and all content types (application/x-www-form-url-encoded and multipart/form-data). And for POST method, it has to be able to get the exact bit-for-bit accurate contents of the POST body.

Now here's the problem: I'm stuck with POST multipart/form-data. The $GLOBALS['HTTP_RAW_POST_DATA'] only works with application/x-www-form-url-encoded. It does not work with multipart/form-data. Neither does $HTTP_RAW_POST_DATA. Same goes for using fopen('php://input', 'rb'). Attempting to read from fopen('php://stdin', 'rb') doesn't return any data at all, regardless of the request method or content-type. The PHP docs have a few clues suggesting it is possible to read from stdin without using the stream fuctions (php://), but I have not found any information on how to do this.

And here's another related dilemma: How does one create a form with a server-side image map and a file upload, and submit it to a PHP script where the script successfully accepts the file and knows the exact names and values of all the form fields? Think about it... you need to use multipart/form-data to submit forms with file uploads. And form-based server-side image maps append a ".x" and ".y" suffix to the form field name to create two more fields containing the X and Y pixel coordinates respectively of where the user clicked on the image. But PHP converts all spaces and periods/decimals/full-stops in form field names to underscores/underlines for the $_GET[], $_POST[], $_COOKIE[], and $_REQUEST[] arrays. So those ".x" and ".y" suffixes become "_x" and "_y". Further, if any form field names contain opening and closing square brackets, PHP turns them into a subarray data type! And if a lone opening square bracket is found, it too becomes an underline/underscore. Without any alternative ways of obtaining the POST data for multipart/form-data submissions, it's impossible for a PHP script to get the true names of the form fields!

There's got to be a solution to this. Any ideas?
Apr 5 '07 #1
2 6087
Uh, quick update.
So using fopen('php://stdin',' rb') does actually work for getting data from stdin on GET requests... only problem is, it's not what I'm looking for. Turns out it's the source code, ie. the code fed to the PHP interpreter! (FYI I'm running PHP as a CGI, not a module.)

It doesn't return any data for POST requests of any sort, but I have a feeling from my GET experience that stdin is not something of interest to me for getting the exact bit-accurate POST body.
Apr 5 '07 #2
And a correction:
I should have typed application/x-www-form-urlencoded in place of application/x-www-form-url-encoded. (Note the last dash/hyphen. blah.) I did have it right in my source code though.
Apr 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Cenker Sisman | last post by:
My problem is I cannot set session variables correctly. I have tried both PHP 4.2.2 and 4.3.3, with register_global is ON. But I cannot manage to see the desired result. My configuration for PHP...
2
by: Erik Johnson | last post by:
I am trying to work with a program that is trying make an HTTP POST of text data without any named form parameter. (I don't know - is that a normal thing to do?) I need to write a CGI program that...
2
by: Kingdom | last post by:
I have a SelectBoxes.asp page that is working with multiple selection dropdown boxes to extract data and total the selection prices. Tom & Bob were kind enough to give me a big help getting this...
4
by: michaelparkin | last post by:
Hi, Sorry to post what might seem like a trivial problem here, but its driving me mad! I have a simple https client that uses httplib to post data to a web server. When I post over http &...
8
by: Bob Skutnick | last post by:
Greetings, I'm hoping someone has experienced a problem I'm having: I have an existing ASP application (working fine) that uses an SSL server certificate. My user community is made up of both...
4
by: Antonio Carpentieri | last post by:
Hi all, in my previous post I've wrong typed some tems.. this is the corrected post. in a aspx page I have a repeater like this: <asp:repeater id=repeaterResults runat="server"...
6
by: murd | last post by:
Hi, I am trying to complete a post using fsockopen but I'm getting the following error: "Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? I am...
9
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo"...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.