|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77314 When doing a http-post-request with a redirect, the post-data is not sent again
Submitted: 2018-12-17 20:52 UTC Modified: 2018-12-18 17:45 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: cyberbeat at gmx dot de Assigned:
Status: Open Package: *Network Functions
PHP Version: 7.2.13 OS: Opensuse
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: cyberbeat at gmx dot de
New email:
PHP Version: OS:


 [2018-12-17 20:52 UTC] cyberbeat at gmx dot de
I make a post request to an url, and get a redirect (to the https version of the page) as a response. In such case, the post data should be sent again to the https-url. But the post data seems not to be sent in the second request.

With CURL (with follow-location-option) this case is handled as expected.

Test script:

$postdata = http_build_query(
        'var1' => 'some content',
        'var2' => 'doh'

$opts = array('http' =>
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata

$context = stream_context_create($opts);

$result = file_get_contents('', false, $context);



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-17 20:59 UTC] spam2 at rhsoft dot net
that simply can't work predictable because params in the redirect-url and hidden fields of the previous post request collides - who should win and why and what result would be the outcome?

what when the page redirects to a 3rd party for whatever reason and you submit sensible post data there?
 [2018-12-17 21:19 UTC]
-Type: Bug +Type: Feature/Change Request
 [2018-12-17 21:19 UTC]
As far as I know, cURL will not automatically re-POST data to the new URL - you have to opt-into that with the CURLOPT_POSTREDIR flag.
Since the pure PHP version operates at a lower level than what the cURL API provides, the equivalent would be checking the response code and repeating the request with the new location.
 [2018-12-18 17:45 UTC] cyberbeat at gmx dot de
Oh, you are right, I have set CURLOPT_POSTREDIR=7, sorry. But perhaps such an option would make sense for php http contexts, too?
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Oct 15 21:03:43 2021 UTC