5

I have a post request to script1.php that redirect with 307 status to script2.php a post request with the same data received in script1.php , my question is if it is possible to alter the post data in script1.php before making the redirect so in script2.php to recieve the new post data? The status doesn't have to be 307 but for what I know only with this one you can redirect a post request but can't alter the data.

Thank you!

Serban Alexandru
  • 165
  • 2
  • 13
  • 1
    So.. According to the spec [a 307](https://tools.ietf.org/html/rfc7231#section-6.4.7) `does not allow changing the request method from POST to GET` - since the purpose of a 307 is to repeat the same request, it provides no mechanism to modify the post data (thankfully - because what a security hole that would be!). – AD7six Dec 12 '16 at 16:37
  • i don't think so, because 307 and 308 basically tell the browser "send the same stuff again, but to another address" - so regardless what you do server-side, the browser sends the same stuff again. or in short: **no**, it's not possible. you *could*, however, proxy the request with curl instead of redirecting, if that fits your requirements. or, if it's on the same server, edit $_POST and include script2.php – Franz Gleichmann Dec 12 '16 at 16:38
  • If it is not important, that the user visits script2.php you can look into curl to send a post on the server side. – colburton Dec 12 '16 at 16:39
  • A 307 still has a uri in a Location header, you could append a query string there, but thats it. iirc a 307 also prompts the user for confirmation. – Alex K. Dec 12 '16 at 16:40
  • The user has to visit script2.php and all the data has to be in POST so I can't add data in query or use curl , as I said 307 status is one possible way if there is another solution that not involves redirect at all or anything that will do what I want is still ok for me . – Serban Alexandru Dec 12 '16 at 16:42
  • Also I can't render a page and use javascript tu auto-submit a form with hidden fields . – Serban Alexandru Dec 12 '16 at 16:43
  • 1
    Include `script2.php` into `script1.php` or what speaks against that? – Charlotte Dunois Dec 12 '16 at 16:55
  • I used script1.php and script2.php to explain but they represent two applications on two different servers and I only have control in the first one. – Serban Alexandru Dec 12 '16 at 16:57
  • Sorry, it's impossible to alter the POST data and redirect with a `3XX` code. You could get it done with Javascript though. Send on form submit an AJAX request to your server, alter the data, send back JSON, process the response with Javascript (alter the form, fill in data etc.) and then submit the form to `script2.php`. – Charlotte Dunois Dec 12 '16 at 17:02
  • Thanks for the answers , unfortunately I can't do this because I don't have access in the client interface , what I have to do is take the request made to my application add some more fields in post data then redirect the client to another application with all the data in post. – Serban Alexandru Dec 12 '16 at 17:06
  • Redirecting with altered data is impossible. You could make the request from your server with curl, otherwise you have no options left. – Charlotte Dunois Dec 12 '16 at 17:08

0 Answers0