Chase Posted February 14, 2007 Share Posted February 14, 2007 Ok, this is a little painless question. I did some research, I wonder myself why I didn't find anything.. I need to read the HTTP request header directly. I know that I can access most parts of it seperatly, but I want it in plain text, all the way from HTTP/.. to the post variables. Is there a way ? Edit: It might be useful to supply a reason: I get a string via POST. However it's lacking the scheme varname1=value1&varname2=value2. It's written in the body directly and I have to access this single string. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 14, 2007 Share Posted February 14, 2007 Try this: http://us2.php.net/reserved.variables Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 14, 2007 Share Posted February 14, 2007 I don't believe you get this, as the header is handled by the web server, and parts of it are passed to the PHP parser. Quote Link to comment Share on other sites More sharing options...
Chase Posted February 14, 2007 Author Share Posted February 14, 2007 Try this: http://us2.php.net/reserved.variables Yeah, I know about reserved variables.. The problem is: The postvariables are lacking the format. Also I wonder what happens if you get something like this: POST /forums/ HTTP/1.1 Host: www.phpfreaks.com Content-Type: application/x-www-form-urlencoded Content-Length: 69 ThisIsjustOneVeryLongStringContainingNothingButNumbersAndCharacters Wouldn't this create one POST-variable without a value but with all the data as a name ? Edit: Basically I don't want the header, it's the body actually Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 14, 2007 Share Posted February 14, 2007 All that information was from those reserved variables. Quote Link to comment Share on other sites More sharing options...
pkSML Posted February 14, 2007 Share Posted February 14, 2007 See http://code-bin.homedns.org/12 to access the raw POST data. Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 14, 2007 Share Posted February 14, 2007 See http://code-bin.homedns.org/12 to access the raw POST data. Okay seriously, it's okay that you're posting these up, but don't use the huge font. That just screams advertising, which is against the rules. Quote Link to comment Share on other sites More sharing options...
Chase Posted February 14, 2007 Author Share Posted February 14, 2007 Let him post it as big as he wants, it's just what I needed! Thanks a thousand times ;D Edit: One more question: What causes the server to write the body into $_POST ? I tried perfectly formatted data (name=Chase&data=12345). It can be read by "php://input", but it doesn't show up in the post-array. Is there some property that needs to be written into the header ? Quote Link to comment Share on other sites More sharing options...
pkSML Posted February 15, 2007 Share Posted February 15, 2007 Let him post it as big as he wants, it's just what I needed! Thanks a thousand times ;D De nada! Edit: One more question: What causes the server to write the body into $_POST ? I tried perfectly formatted data (name=Chase&data=12345). It can be read by "php://input", but it doesn't show up in the post-array. Is there some property that needs to be written into the header ? Did you try this: <?php echo "<PRE>"; print_r($_POST); echo "</PRE>"; ?> This will output all POST variables. Most likely, variable names are getting mixed up. This is very easy to do. I would recommend getting ieHTTPheaders and you can see all HTTP headers (and post data). Very useful tool. Quote Link to comment Share on other sites More sharing options...
Chase Posted February 16, 2007 Author Share Posted February 16, 2007 Yes, I tried writing out the post array, the variables don't show up in there. The problem is: I don't get the data from a browser; The header is written by an application. It's actually not my job to manipulate this application but if there's something missing in the header I see what I can do. So, what causes PHP to put the variables into the $_POST array ? Would be a better solution than parsing file_get_contents("php://input") myself... Quote Link to comment Share on other sites More sharing options...
pkSML Posted February 16, 2007 Share Posted February 16, 2007 That's very awkward. It must be the format of the HTTP header. Can you grab the application's HTTP request headers? $_POST Variables provided to the script via HTTP POST. Analogous to the old $HTTP_POST_VARS array (which is still available, but deprecated). Sounds like PHP automatically does this. Here is a post header made at http://stephen.calvarybucyrus.org/contact POST /contact/sendmail_simple.php HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */* Referer: http://stephen.calvarybucyrus.org/contact Accept-Language: en-us Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322) Host: stephen.calvarybucyrus.org Content-Length: 149 Connection: Keep-Alive Cache-Control: no-cache name=stephen&email=anybody@calvarybucyrus.org&subject=testing+http+headers&message=just+testing+this+message+to+see+how+a+proper+post+request+is+made I'll guess your problem is in how many carriage returns are separating the header and the post information. Also check out: http://www.jmarshall.com/easy/http/#postmethod Quote Link to comment Share on other sites More sharing options...
Chase Posted February 17, 2007 Author Share Posted February 17, 2007 Yeah that's it. It's not the number of line-breaks, but as I was expecting there is a RequestProperty that tells PHP to put the data into the $_POST array - it's the "Content-Type". When this is not set to "application/x-www-form-urlencoded" it won't work. Changed that in the app, now everything shows up. How I love fixing other ppls code Thanks a lot. Quote Link to comment Share on other sites More sharing options...
pkSML Posted February 17, 2007 Share Posted February 17, 2007 You're welcome. Glad it's fixed for ya'! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.