php ipn自定义变量不起作用

时间:2014-10-18 17:47:31

标签: php paypal

我有这个按钮:

 <button name="pay">BUY FOR 0.50$</button>
点击后,它会将付款$ 0,买家IP和帐户明细的付款插入到DB中:

$connect->query("INSERT INTO payments(ip,payed,acc,showed) VALUES('$ip','$payed', '$s', '$h')");

   echo '
<form action="https://www.paypal.com/cgi-bin/webscr" id="formsend" method="post" target="_top">
  <input type="hidden" name="cmd" value="_xclick">
  <input type="hidden" name="business" value='.$paypal.'>
  <input type="hidden" name="lc" value="US">
  <input type="hidden" name="item_name" value="LOL ACC">
  <input type="hidden" name="amount" value="0.50">
  <input type="hidden" name="currency_code" value="USD">
  <input type="hidden" name="custom" value="<?=$ip;?>">
  <input type="hidden" name="button_subtype" value="services">
  <input type="hidden" name="no_note" value="0">
  <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
  <input type="submit" name="sub" class="sub" />
</form>
   ';
?>

<script type="text/javascript">
    document.getElementById('formsend').submit(); // SUBMIT FORM
</script>

之后,如果Paypal工作正常,它会自动点击新表单进行付款。但是在IPN上变量custom没有传递IP地址。

这是在IPN验证部分内:

require_once("config/config.php");
$connect =  new mysqli($server['database']['host'],$server['database']['username'],$server['database']['password'],$server['database']['db']);

// PAYMENT VALIDATED & VERIFIED!

$ip = $_POST['custom'];
$check = $connect->query("SELECT * FROM payments WHERE ip='$ip' AND payed = 0");

if($check->num_rows){
  $connect->query("UPDATE payments SET payed = 1 WHERE ip = '$ip'");
}

我也试过插入一个随机字符串,但这似乎也不起作用。我做错了什么?

1 个答案:

答案 0 :(得分:0)

由于单引号内的<?php?> ,因此不会对其进行解析。为此,您应该使用字符串连接运算符,如下所示:

echo '<form...>
<input type="hidden" name="custom" value="' . $ip . '">
</form>';