Page 1 of 1

Redirect: cURL vs. header

Posted: Wed May 27, 2009 1:56 am
by MmmVomit
I'm having a little trouble using cURL to redirect.

I have a form that collects some data and stores it in the SESSION array. After everything is collected, I redisplay this information to verify that it is correct. Upon verification, I want to write the user info to the database, then redirect and post information to paypal.

I can easily redirect using the header function, and this gives me exactly the behavior I'm looking for minus the post data. I've figured out how to post data using cURL, but it doesn't redirect to the new page the way I'd like it too.

Here's some test code. The file name is redir.php.

Code: Select all

<?php
$cs = curl_init("http://www.mysite.com/post.php");
 
curl_setopt($cs, CURLOPT_POST, 1);
curl_setopt($cs, CURLOPT_POSTFIELDS, "fso=dhgick&bar=face");
curl_setopt($cs, CURLOPT_FOLLOWLOCATION, 1);
 
curl_exec($cs);
curl_close($cs);
 
?>
Instead of actually redirecting to the page post.php, it seems to pull content in from post.php and incorporate it in the output of redir.php.

Re: Redirect: cURL vs. header

Posted: Thu May 28, 2009 2:05 pm
by Darhazer
When you are using cURL, the information is exchanged between your server and the third party server.
To redirect the user to the third party server, you have to tell his browser to do this.
However you can not tell the browser to post something to the server, not with the header
You can output a hidden form and submit it with javascript, so you will force the browser to post the data to the third party server.