1

I'm trying to access the raw HTTP request sent to the server in PHP.

However, all the input/output streams are not working.

I can't use php://input, and I don't want to have to "interpolate" the request from the arrays such as $_COOKIES, $_POST, etc. $_POST, $_GET and the other arrays are working fine. I'm using WAMPServer on Windows 7.

Can anyone help me fix the problem with the input/output streams or find another way to get the raw request data?

Mehdi
  • 1,494
  • 5
  • 33
  • 53
user1359533
  • 13
  • 1
  • 3
  • If `php://input` doesn't work, I doubt that other options will work. – Konrad Borowski Apr 27 '12 at 12:39
  • 2
    They don't exist. They're treated like files that don't exist. For example, file_exists("php://input") returns false. – user1359533 Apr 27 '12 at 12:40
  • 1
    Also, possible duplicate of http://stackoverflow.com/questions/5463596/php-input-returning-empty-string – Konrad Borowski Apr 27 '12 at 12:40
  • Please consult the PHP Manual, there are limitations with `php://input`, it's not always available, see here: http://php.net/manual/wrappers.php.php - If you need it for the cases it's documented it is not available, please update your question accordingly so that we can tell you how to re-compile PHP w/o such limitations. – hakre Apr 27 '12 at 12:47
  • @zerkms probably because the content type of the request is `multipart/form-data` and he didn't read [the documentation](http://php.net/manual/en/wrappers.php.php) properly... – DaveRandom Apr 27 '12 at 12:47
  • GET /test/HS404.php?lolz=derp HTTP/1.1 Host: localhost Connection: keep-alive Cache-Control: max-age=0 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 Cookie: PHPSESSID=qeqeqweqeqweqeqw – user1359533 Apr 27 '12 at 13:00

1 Answers1

0

From the PHP docs:

php://input is a read-only stream that allows you to read raw data from the request body

which means you can only read body data, not headers or the raw request. If you're running under Apache, you can use the function apache_request_headers to get all the headers. To get the "request" line (the first line of the request), I suppose you need to concat the strings you can get from the $_SERVER variable.

kuba
  • 7,329
  • 1
  • 36
  • 41
  • For `If you're running under Apache` read `if you're running as an Apache module`. It doesn't work in CGI mode. However it *does* work when running as FastCGI, or as an NSAPI module. – DaveRandom Apr 27 '12 at 12:55
  • 1
    Really? So there isn't a way to get the raw request? – user1359533 Apr 27 '12 at 15:31