为什么帖子数据没有反映在页面上?

时间:2012-02-07 11:01:58

标签: php paypal

我在我的网站上使用此代码,用于paypal结帐

<?php

require('../includes/globals/config.php');
require('myCart.inc.php');

$mycart = new myCart;
$ppemail = $mycart->getPaypalEmail();

  $paypal_email = $ppemail['email'];
  $paypal_currency = 'USD';
 //$shipping = 1.00;



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

foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// 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.sandbox.paypal.com', 80, $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'];



if (!$fp){
// HTTP ERROR
} else {
fputs($fp, $header . $req);
while(!feof($fp)) {
$res = fgets($fp, 1024);
if (strcmp($res,"VERIFIED") == 0){

//blah blah

}
else if (strcmp($res, "INVALID") == 0){
// log for manual investigation
}
}
fclose($fp);
}
?>

问题是,在事务处理之后,我被重定向到感谢页面,$ _POST数据没有出现在表单输入上,我的意思是,我提取了来自的$ _POST数据的内容paypal交易并将数据的花絮放在每个表单字段上。但是当我清理浏览器缓存/私有数据/会话/ cookie并执行相同的程序时,这次用

echo "<pre>",print_r($_POST),"</pre>";

$ _POST内容被打印在页面上,$ _POST的花絮也显示在表单字段中..当我使用print_r时会发生这种情况。这有解决方法吗?这样数据的花絮就会立即显示在表单字段上,而不必调用print_r()函数并在页面的某处打印数据数组?

0 个答案:

没有答案