Jump to content

Passing Variables to a URL


millsy007

Recommended Posts

I have some code that I dont exactly undertsand and wanted some help adding to.

 

I believe this code uses an external link (paypal) and passes additional variables to the URL?

 

// post back to PayPal system to validate	
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


// assign posted variables to local variables
$item_name 			= $_POST['item_name'];
$item_number 		= $_POST['item_number'];
$payment_status 	= $_POST['payment_status'];
$payment_amount 	= $_POST['mc_gross'];
$payment_currency 	= $_POST['mc_currency'];
$txn_id 			= $_POST['txn_id'];
$receiver_email 	= $_POST['receiver_email'];
$payer_email 		= $_POST['payer_email'];
$custom 			= $_POST['custom'];

if (!$fp) {
// HTTP ERROR
} else {

 

Could I simply add to the URL by passing in an additional variable?

Link to comment
Share on other sites

Okay apologies I think I posted the wrong function perhaps.

Is this the part that carries out the functionality I described?

 

function pdt_response(){

// read the post from PayPal system and add 'cmd'
$req 		= 'cmd=_notify-synch';

$tx_token 	= $_GET['tx'];
$auth_token = get_option('wps_paypal_pdttoken');
$req 		.= "&tx=$tx_token&at=$auth_token";

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp 	= fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
	// HTTP ERROR
} else {
	fputs ($fp, $header . $req);
	// read the body data 
	$res = '';
	$headerdone = false;
	while (!feof($fp)) {
		$line = fgets ($fp, 1024);
		if (strcmp($line, "\r\n") == 0) {
			// read the header
			$headerdone = true;
		}
		elseif ($headerdone)
		{
			// header has been read. now read the contents
			$res .= $line;
		}
	}

	// parse the data
	$lines 		= explode("\n", $res);
	$keyarray 	= array();
	if (strcmp ($lines[0], "SUCCESS") == 0) {
		for ($i=1; $i<count($lines);$i++){
			list($key,$val) = explode("=", $lines[$i]);
			$keyarray[urldecode($key)] = urldecode($val);
		}


		$PDT_DATA 	= array();

		$PDT_DATA[firstname] 		= $keyarray['first_name'];
		$PDT_DATA[lastname] 		= $keyarray['last_name'];
		$PDT_DATA[itemname] 		= $keyarray['item_name'];
		$PDT_DATA[amount] 			= $keyarray['mc_gross'];
		$PDT_DATA[currency] 		= $keyarray['mc_currency'];	

		$PDT_DATA[payment_status]	= $keyarray['payment_status']; 
		$PDT_DATA[payment_type] 	= $keyarray['payment_type'];
		$PDT_DATA[pending_reason] 	= $keyarray['pending_reason'];
		$PDT_DATA[who] 				= $keyarray['custom'];



		$ERROR 		= 0;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.