How to redirect a webpage request while keeping all POST variables to another PHP page
March 22, 2007 9:01 AM   RSS feed for this thread Subscribe

Is there an easy way in PHP to send all the POST variables submitted in a form to another webpage?

I am currently using the PayPal API for some shopping cart/order management things I've custom written. For a short period of time, I need to use two different IPN scripts. The way the IPN for PayPal works is that data is sent from PayPal to a PHP script on my website with a number of POST variables. I would like to send that same page request (with the post variables in tact) to another PHP script/page. Is there an easy way to redirect the web page request PayPal sends to another web page, with all the POST variables in tact after it has been received on my site?

Is there some straightforward way to do this?
posted by JakeWalker to computers & internet (4 comments total) 1 user marked this as a favorite
Yeah, use curl to post to another page.

Something like this should work:

$url = "/path/to/new/page.php";
$params = "$username_field_id=$username&$password_field_id=$password"; // put whatever variables you need here. you can read them in from your last page by doing $variable=$_POST['variable_name']
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

$connection = curl_init();
curl_setopt($connection, CURLOPT_POST,1);
curl_setopt($connection, CURLOPT_POSTFIELDS,$params);
curl_setopt($connection, CURLOPT_URL,$url);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($connection, CURLOPT_USERAGENT, $user_agent);
curl_setopt($connection, CURLOPT_RETURNTRANSFER,1);
curl_setopt($connection, CURLOPT_VERBOSE, 1); //for debugging purposes
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, FALSE); // this line makes it work under https

$result=curl_exec ($connection);
echo("Results: ".$result); // debugging purposes

posted by jeffxl at 9:12 AM on March 22, 2007


Can't you just 301 redirect?
posted by Rhomboid at 10:37 AM on March 22, 2007


301 redirect worked like a charm.

Just saved me a bunch of hassle. Thanks!
posted by JakeWalker at 11:37 AM on March 22, 2007


Well, sure, if you want simplicity you could use a 301... :)
posted by jeffxl at 12:47 PM on March 22, 2007


« Older Anyone know of a free DNS syst...   |   International Driving Permit: ... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Paypal alternatives May 13, 2008
Open Source Shopping Cart April 8, 2008
PayPal considered right-wing? January 12, 2008
How to go about managing payments in a web app? September 10, 2007
I need a basic website template with paypal as... May 3, 2007