Paypal IPN $ custom不能使用PHP

时间:2015-07-29 14:23:16

标签: php paypal

我有一个paypal听众,邮件设置和工作正常,但我想通过一个" custom"变量到paypal在我的IPN中返回以更新我的数据库。听众正在使用IPN模拟器,但我已将其缩小到注册页面,而不是发送" custom"信息。我不能用任何方式熟悉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); ?>"

有人可以指导我正确使用这个吗?

1 个答案:

答案 0 :(得分: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。 '方法而不是。

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

我刚才读到某个地方,最好尽可能多地使用单引号,因为如果你使用双引号,那么PHP会在该内容中查找$ phpvars,这会削弱服务器上的一些处理能力。