Forwarding POST data to PayPal - SOLVED

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
Black Unicorn
Forum Commoner
Posts: 48
Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom

Forwarding POST data to PayPal - SOLVED

Post 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
Last edited by Black Unicorn on Tue Mar 28, 2006 8:19 am, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

use cURL instead :wink:
Black Unicorn
Forum Commoner
Posts: 48
Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom

Post by Black Unicorn »

Thanx ;)

I will give that a go.
Post Reply