Page 1 of 1

Forwarding POST data to PayPal - SOLVED

Posted: Tue Mar 28, 2006 7:15 am
by Black Unicorn
Hi all!

I have a problem I simply can't figure out.
I have a basket for use with paypal, however instead of letting the HTML for post directly (as would be the norm) I am trying to forward it instead, to allow some processing to be done.

I've researched to the point where fsockopen() seems the way to go, but PayPal doesn't like it, plus it puts the HTTP headers on the page!

Here's my script:

Code: Select all

$out = '';
foreach($_POST as $key=>$val){
	$out.= $key."=".urlencode(stripslashes($val))."&";
}
$post = "POST cgi-bin/webscr HTTP/1.1\r\n";
$post.= "Host: www.paypal.com\r\n";
$post.= "Content-type: application/x-www-form-urlencoded\r\n";
$post.= "Content-length: ";
$post.= strlen($out)."\r\nConnection: close\r\n\r\n$out";
$fp = fsockopen("www.paypal.com", 80 , $errno, $errstr);
if (!$fp)die("Uh, oh.");
fwrite($fp,$post);
while (!feof($fp)) {
      echo fgets($fp, 128);
}
fclose($fp);
I can't for the life of me find any reference or resource as to the anatomy of the POST request as sent from the browser.

Best regards,
H

Posted: Tue Mar 28, 2006 7:45 am
by John Cartwright
use cURL instead :wink:

Posted: Tue Mar 28, 2006 8:19 am
by Black Unicorn
Thanx ;)

I will give that a go.