Redirect: cURL vs. header

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MmmVomit
Forum Newbie
Posts: 4
Joined: Wed May 27, 2009 1:09 am

Redirect: cURL vs. header

Post 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.
Last edited by Benjamin on Wed May 27, 2009 9:54 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Redirect: cURL vs. header

Post 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.
Post Reply