我试图传递一个自定义变量trought paypal按钮并使用ipn获取值,即时通讯使用此隐藏字段:
<input type="hidden" name="custom" value="<?php echo"".$username.""; ?>">
这是我的完整按钮:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin-left:32px;" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo"".$settings['admin']['paypal'].""; ?>">
<input type="hidden" name="lc" value="PT">
<input type="hidden" name="item_name" value="account">
<input type="hidden" name="custom" value="<?php echo"".$username.""; ?>">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="amount" value="<?php echo"".$item_catch['price']."";?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
这是我的ipn听众:
<?php
// 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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// PAYMENT VALIDATED & VERIFIED!
$username = $_POST['custom'];
$add = $connect->prepare("INSERT INTO purchases(fromm) VALUES(?)");
$add->bind_param("s", $username);
$add->execute();
$add->close();
}
else if (strcmp ($res, "INVALID") == 0) {
// PAYMENT INVALID & INVESTIGATE MANUALY!
}
}
fclose ($fp);
}
问题是我没有得到自定义变量,并且它继续在fromm上插入数据库null
答案 0 :(得分:0)
你的报价太多了:
<input type="hidden" name="custom" value="<?php echo $username; ?>">