Jump to content

Read the header?


Chase

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/#findComment-184768
Share on other sites

Let him post it as big as he wants, it's just what I needed!

Thanks a thousand times  ;D ;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 ?

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/#findComment-184821
Share on other sites

Let him post it as big as he wants, it's just what I needed!

Thanks a thousand times  ;D ;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.

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/#findComment-185024
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/#findComment-186482
Share on other sites

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 protected]&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

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/#findComment-186629
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/38509-read-the-header/#findComment-186729
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.