开发者

PHP: Simulate a <form> tag with POST data and also redirecting the user

I have been scouring the internet for a way to do this with no luck :( Basically, it's easy to make a form in HTML with a submit button and some data, and send it to a URL. With this you send the POST data and开发者_Go百科 also the user is taken to the page.

I know you can send POST data using cURL and get a response back in PHP but how do I take the user there, I need to simulate exactly what a tag does in php.

Some sample code or links would be great!


If you want the user to see the resulting page, you have two options:

  • Proxy the result to the user. This isn't as simple as it sounds, due to link URLs and whatnot, and might not even be what you want.
  • Don't use PHP at all, create the form in HTML (lots of hidden inputs) and submit it via JavaScript.


In cURL, use curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);. This will display the result to screen rather than returning it to a string. If the other site typically redirects after the form is submitted, then the redirect will occur as well and will take you to the new page.


If you really need to redirect the user to another page after the submission (instead of just showing the result on the same page), you can use a header ("Location: http://www.yourdomain.com/resultpage"); after the PHP handles the cURL call with the POST data. I'm curious though why you do not want to output the results of the cURL call immediately.

It sounds like you're consuming a web service. Are you?

Maybe a more detailed description of what you are trying to achieve would be helpful.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜