gpt4 book ai didi

php - Paypal IPN $自定义变量不适用于 PHP

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:30 24 4
gpt4 key购买 nike

我有一个 paypal 监听器,设置了邮件并且工作正常,但我正在尝试将“自定义”变量传递给 paypal 以返回我的 IPN 以更新我的数据库。监听器正在使用 IPN 模拟器,但我已将其缩小到不发送“自定义”信息的注册页面。我对 php 一点都不流利,下面是我在 paypal 按钮上使用的代码:

<?php
if(!empty($_POST['name']))
{
$name = mysql_real_escape_string($_POST['name']);
$phone = mysql_real_escape_string($_POST['phone']);
$email = mysql_real_escape_string($_POST['email']);
$address = mysql_real_escape_string($_POST['address']);
$date = mysql_real_escape_string(date("Y.m.d"));
$active = mysql_real_escape_string('Active - Not Paid');
$supportrec = isset($_POST['supportboatsyes']);
$support10hpban = isset($_POST['support10hpbanyes']);
$supporttotalban = isset($_POST['supporttotalbanyes']);
$emaillist = isset($_POST['addtoemailyes']);
$volunteer = mysql_real_escape_string($_POST['volunteer']);

$checkusername = mysql_query("SELECT * FROM recreationUsers WHERE Name = '".$name."'");

if(mysql_num_rows($checkusername) == 1)
{
echo "<h1>Error</h1>";
echo "<p>Sorry, you have already registered. <br /> Please contact the site administrator regarding any issues.</p>";
}
else
{
$registerquery = mysql_query("INSERT INTO recreationUsers (Name, Phone, Email, Address, Date_added, Status, Support_all_recreation, Support_10hp_ban, Support_no_boats, Email_list, Volunteer) VALUES('".$name."', '".$phone."', '".$email."', '".$address."', '".$date."', '".$active."', '".$supportrec."', '".$support10hpban."', '".$supporttotalban."', '".$emaillist."', '".$volunteer."')");
if($registerquery)
{
$custom = mysql_real_escape_string($_POST['name']);

echo "<h1>Success, please choose your account type below:</h1>";
echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="6F6YP6CVBRW92" />
<input type="hidden" name="custom" value="$custom" />
<table>
<tr><td><input type="hidden" name="on0" value="Choose a subscription:" />Choose a subscription:</td></tr>
<tr>
<td>
<select name="os0">
<option value="Individual">Individual: $20.00 CAD - Annual</option>
<option value="Family">Family: $50.00 CAD - Annual</option>
</select>
</td>
</tr>
</table>
<input type="hidden" name="currency_code" value="CAD" />
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_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>';

echo "<p>If you don't have a Paypal account Please Click on the next page \"Pay using your credit or debit card.\"</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please go back and try again.</p>";
}
}
}
else
{
?>

我也试过:

<input type="hidden" name="custom" value="<?php echo htmlspecialchars($custom); ?>"

和:

 <input type="hidden" name="custom" value="<?php echo $custom); ?>"

谁能指导我正确使用它?

最佳答案

这将使表单输出正确填写自定义参数(假设 $custom 以您期望的方式填充。)

echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="bn" value="AngellEYE_SP_GeneralConsult" />
<input type="hidden" name="hosted_button_id" value="6F6YP6CVBRW92" />
<input type="hidden" name="custom" value="'. $custom . '" />
<table>
<tr><td><input type="hidden" name="on0" value="Choose a subscription:" />Choose a subscription:</td></tr>
<tr>
<td>
<select name="os0">
<option value="Individual">Individual: $20.00 CAD - Annual</option>
<option value="Family">Family: $50.00 CAD - Annual</option>
</select>
</td>
</tr>
</table>
<input type="hidden" name="currency_code" value="CAD" />
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_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>';

为了进一步解释,您使用单引号打开您的 echo 语句。因此,仅在内部使用 $custom 不会实际输出 $custom 的值,因此您需要使用 ' 。 $自定义。 ' 方法代替。

如果您使用双引号打开回显行,那么直接使用 $custom 就可以了,但是您还必须转义 html 表单中的所有双引号,因为它们会关闭回显行如果他们没有逃脱。

我不久前在某处读到,最好尽可能多地使用单引号,因为如果您使用双引号,那么 PHP 将在该内容中查找 $phpvars,这会消耗服务器上的一些处理能力。

关于php - Paypal IPN $自定义变量不适用于 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31703280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com