开发者

POST in PHP AND redirect the user to that page?

I'm a bit con开发者_Python百科fused. How do I POST data to a URL and then redirect the user's browser to that location - all in one operation?

I see

header('Location: page.php?' . http_build_query($_POST)); 

but that is GET, not POST and ppl think thats really bad practice - PHP open another webpage with POST data (why?)

My kludgy workflow involves setting up a form and then submitting it via javascript - anything has to be better than that...

I think I can do a set of header() stmts but this action happens for the user way after the page has been geenrated, so i dont think that would work


You cannot redirect POST requests. As simple as that. Any redirect will always turn into a GET request.

If you want to receive POST data, then send that data to another page, you have two choices:

  • if both pages are on the same server, use sessions to save the data server-side, don't make the client carry it over
  • if the destination is on another server and you need to send the client there together with the data, set up another intermediate form like you are


Use AJAX to save the data before you leave the page. Use the answer you get back to fire a redirection to the new url right within the current page. Don't be affraid of Javascript and ajax. Try this light AJAX library: http://www.openjs.com/scripts/jx/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜