tags:

views:

212

answers:

3

Hi,

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 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! Thanks in advanced...

+2  A: 

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.
Matti Virkkunen
A: 

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.

squall3d
A redirect will cause a new GET request from the browser, so this works only if the result page has a unique URL, and doesn't directly use POST data.
Matti Virkkunen
It needs to directly use the POST data... like a form.
tarnfeld
Matti Virkkunen: I meant generating the header after the php page has handled the POST data. At least that's what I am guessing tarnfeld is trying to do.
squall3d
Tarnfeld: Correct me if I got you wrong: You want to post the form to the server, send the POST data to somewhere else with cURL, then bring the viewer to a different result page? Is there anything preventing you from simply returning the results of the cURL call on the php result page? Also, you sound like you're simply trying to consume a web service, if that's the case let me know too.
squall3d
A: 

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.

Joseph