From: mike dot hall at twistdigital dot co dot uk Operating system: Ubuntu 12.04 PHP version: 5.4.4 Package: Streams related Bug Type: Bug Bug description:fopen follows redirects for non-3xx statuses
Description: ------------ The HTTP location header can either be used to direct the user to another resource (when accompanied by a 3xx status code) or to inform the user of the location of the document they just created (with a 2xx) status code. It doesn't make sense to treat the location header as a redirect in the second context - the location header indicates a redirect only when accompanied by a 3xx status code. Currently, PHP follows Location headers as if they are redirects regardless of the returned status code. Test script: --------------- $context = stream_context_create([ "http" => [ "method" => "POST" "header" => "Content-Length: 13" "content" => "{\"foo\":\"bar\"}", ], ]); // Returns HTTP/1.1 201 Created // Location: http://example.com/mydb/documentid // // {"status":"ok"} $fp = fopen('http://example.com/mydb', 'r', null, $context); $data = stream_get_contents($fp); list($headers, $body) = explode("\r\n\r\n", $data, 2); echo $body; Expected result: ---------------- {"status":"ok"} Actual result: -------------- {"foo":"bar"} -- Edit bug report at https://bugs.php.net/bug.php?id=62524&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=62524&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=62524&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=62524&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=62524&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62524&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=62524&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=62524&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=62524&r=needscript Try newer version: https://bugs.php.net/fix.php?id=62524&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=62524&r=support Expected behavior: https://bugs.php.net/fix.php?id=62524&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=62524&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=62524&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=62524&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=62524&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=62524&r=dst IIS Stability: https://bugs.php.net/fix.php?id=62524&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=62524&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=62524&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=62524&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=62524&r=mysqlcfg