Is it possible to send POST data with a PHP redirect?

前端 未结 10 2460
一个人的身影
一个人的身影 2021-02-14 05:04

Update: This is NOT a duplicate of How do I send a POST request with PHP?. The solutions there don\'t work for me, they just output the result of the request, I don\'t w

10条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 05:32

    Short answer :

    • POST to external server
    • parse response
    • do not echo out anything
    • use header('Location: url?param=res') ;
    • exit ; //this is kind of important

    I do not want to receive the result of the POST request in my PHP script, instead I just want to send the user to the external site where they see the result of the POST

    If you are sending a POST request from a PHP script, then the response will ALWAYS come back to the same PHP script. I think what you want is NOT to send this the response back to the user, but instead redirect the user to a another URL. For which you make sure you are doing.

    header('Location: url?param=res') ;
    exit ;
    

    and not sending anything to the client before the header() call

提交回复
热议问题