php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59239 http_get_request_headers returns nothing after php://input on a PUT request
Submitted: 2010-05-27 19:48 UTC Modified: 2010-06-09 03:36 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: timtrinidad at gmail dot com Assigned:
Status: Wont fix Package: pecl_http (PECL)
PHP Version: 5.2.10 OS: Ubuntu
Private report: No CVE-ID: None
 [2010-05-27 19:48 UTC] timtrinidad at gmail dot com
Description:
------------
Reading the PHP input stream with the fopen('php://input') routine before calling http_get_request_body() on a PUT HTTP request.

Here are some examples:

A POST request:
*********************************************************
PUT http://example.com/requestbodytest.php HTTP/1.1
Host: example.com
Keep-Alive: 300
Connection: keep-alive
Content-Type: text/xml
Content-Length: 58

<?xml version="1.0" encoding="utf-8" ?>
<body>test</body>
*********************************************************


with the following script:
*********************************************************
<?php
$body = '';
$fh   = @fopen('php://input', 'r');
if ($fh)
{
  while (!feof($fh))
  {
    $s = fread($fh, 1024);
    if (is_string($s))
    {
      $body .= $s;
    }
  }
  fclose($fh);
}
print("-------------- PHP Input Stream ----------------\n$body\n\n");

$body2 = http_get_request_body();
print("---------- http_get_request_body() -------------\n$body2\n\n");

?>
*********************************************************


outputs this:
*********************************************************
-------------- PHP Input Stream ----------------
<?xml version="1.0" encoding="utf-8" ?>
<body>test</body>

---------- http_get_request_body() -------------
<?xml version="1.0" encoding="utf-8" ?>
<body>test</body>
*********************************************************


The same request to the same script using an HTTP PUT request, however, outputs this:
*********************************************************
-------------- PHP Input Stream ----------------
<?xml version="1.0" encoding="utf-8" ?>
<body>test</body>

---------- http_get_request_body() -------------
*********************************************************




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-09 03:36 UTC] mike@php.net
Quote http://php.net/manual/en/wrappers.php.php

Note: php://input can only be read once.

Sorry, this is a insuperable limitation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC