【问题标题】:Paypal IPN $custom Variable not working with PHPPaypal IPN $custom 变量不适用于 PHP
【发布时间】:2015-07-29 14:23:15
【问题描述】:

我有一个带有邮件设置的贝宝监听器,工作正常,但我试图将一个“自定义”变量传递给贝宝,以返回我的 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); ?>"

谁能指导我正确使用这个吗?

【问题讨论】:

  • 为什么要在 html 表单值上使用 sql 转义?反斜杠在 html 中完全没有意义,并且是一个常规字符。
  • 我正在阅读一个论坛,它对某人有用,对不起,我完全迷路了,我不知道该去哪里。
  • 你已经设置了一个变量$name为什么又$custom你可以使用$name
  • 所以这应该有效吗? &lt;input type="hidden" name="custom" value="$custom" /&gt;

标签: php paypal


【解决方案1】:

这将使表单输出正确填写自定义参数(假设 $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,这会消耗服务器上的一些处理能力。

【讨论】:

  • 我不会担心所谓的单引号提高效率 - 它是如此微不足道,不值得打扰。使用更具可读性的内容。在这个主题上,在echo 语句中捕获大块 HTML 并不理想,因为这样会丢失 IDE 的语法分析、标记匹配和代码着色。最好在 PHP 的 HTML 模式下渲染 HTML,并为动态位临时闯入 PHP。或者,当然,使用模板引擎。
  • 谢谢!!现在完美运行!我需要深入研究一下它的 php 语法!
猜你喜欢
  • 2020-07-19
  • 2020-09-25
  • 2016-07-13
  • 2012-01-02
  • 2011-02-27
  • 2017-08-08
  • 2012-08-24
  • 1970-01-01
  • 2015-06-01
相关资源
最近更新 更多