Paypal IPN变量PHP

Paypal IPN变量PHP,php,html,paypal,paypal-ipn,Php,Html,Paypal,Paypal Ipn,嗨,我正在努力建立ipn,但我对php非常陌生,我以为我已经弄明白了,但还没有接近:) 不管怎么说,我想做的就是在付款后,在一个文本文件中写下人的名字,然后在旁边的文本字段中写下他们的输入,我在我的按钮中做了这样的输入 <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input

嗨,我正在努力建立ipn,但我对php非常陌生,我以为我已经弄明白了,但还没有接近:)

不管怎么说,我想做的就是在付款后,在一个文本文件中写下人的名字,然后在旁边的文本字段中写下他们的输入,我在我的按钮中做了这样的输入

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5ES3TSKJNLJ24">
<table style="text-align: right; width: 100%;">
<tr><td><input type="hidden" name="on0" value="Amount you'd like to donate">Amount you'd like to donate</td></tr><tr><td><select name="os0">
    <option value="Just the license">Just the license $2.99 USD</option>
    <option value="A bit more">A bit more $5.99 USD</option>
    <option value="Two bits more">Two bits more $8.99 USD</option>
    <option value="A lot more">A lot more $15.00 USD</option>
    <option value="We love you :)">We love you :) $50.00 USD</option>
</select> </td></tr>
<tr><td><input type="hidden" name="on1" value="Primary Phone Gmail">Primary Phone Gmail</td></tr><tr><td><input type="text" name="os1" maxlength="200"></td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" align="right" 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>
<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following: 
// To continue posting back to https://www.paypal.com  to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify  your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."


// 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";

    // If testing on Sandbox use: 
    // $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: ipnpb.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    // If testing on Sandbox use:
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$payer_firstName = $_POST['first_name'];
$payer_lastName = $_POST['last_name'];
$gmail = $_POST['on1'];

//set email variables
$From_email = "From: fake@website.com";
$Subject_line = "Thanks for your purchase";

$email_msg = "\n\nThe details of your order are as follows:";
$email_msg .= "\n\n" . "Transaction ID: " .  $txn_id ;
$email_msg .= "\n" . "Payment Date: " . $payment_date;

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

$mail_From = $From_email;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

$data = "$payer_firstName $payer_lastName $gmail";

$fh = fopen("./paypal/test.txt", "a");
fwrite($fh, $data);
fclose($fh);

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = $From_email;
$mail_To = $receiver_email;
$mail_Subject = "INVALID IPN POST";
$mail_Body = "INVALID IPN POST. The raw POST string is below.\n\n" . $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>

您想捐赠的金额
只要许可证2.99美元
5.99美元多一点
再多一点8.99美元
还要多15美元
我们爱你:)$50.00美元
主要电话Gmail
我的ipn.php如下所示

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="5ES3TSKJNLJ24">
<table style="text-align: right; width: 100%;">
<tr><td><input type="hidden" name="on0" value="Amount you'd like to donate">Amount you'd like to donate</td></tr><tr><td><select name="os0">
    <option value="Just the license">Just the license $2.99 USD</option>
    <option value="A bit more">A bit more $5.99 USD</option>
    <option value="Two bits more">Two bits more $8.99 USD</option>
    <option value="A lot more">A lot more $15.00 USD</option>
    <option value="We love you :)">We love you :) $50.00 USD</option>
</select> </td></tr>
<tr><td><input type="hidden" name="on1" value="Primary Phone Gmail">Primary Phone Gmail</td></tr><tr><td><input type="text" name="os1" maxlength="200"></td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="image" align="right" 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>
<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following: 
// To continue posting back to https://www.paypal.com  to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify  your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."


// 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";

    // If testing on Sandbox use: 
    // $header .= "Host: www.sandbox.paypal.com:443\r\n";
$header .= "Host: ipnpb.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    // If testing on Sandbox use:
    //$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$payer_firstName = $_POST['first_name'];
$payer_lastName = $_POST['last_name'];
$gmail = $_POST['on1'];

//set email variables
$From_email = "From: fake@website.com";
$Subject_line = "Thanks for your purchase";

$email_msg = "\n\nThe details of your order are as follows:";
$email_msg .= "\n\n" . "Transaction ID: " .  $txn_id ;
$email_msg .= "\n" . "Payment Date: " . $payment_date;

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

$mail_From = $From_email;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

$data = "$payer_firstName $payer_lastName $gmail";

$fh = fopen("./paypal/test.txt", "a");
fwrite($fh, $data);
fclose($fh);

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

$mail_From = $From_email;
$mail_To = $receiver_email;
$mail_Subject = "INVALID IPN POST";
$mail_Body = "INVALID IPN POST. The raw POST string is below.\n\n" . $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

}
}
fclose ($fp);
}
?>


我已经弄明白了,我花了一整天的时间(在凌晨3:40开始工作),但是一天之内就学会了很多php哈,我会在几分钟后发布我所做的事情。你为什么要检查神奇的引用?此选项已被弃用,任何人都不应使用它。这给你的代码增加了额外的复杂性。我刚刚从paypal复制并粘贴了这个例子。我真的不太懂php,这就是为什么我遇到麻烦的原因。我的php知识的扩展是写一个文本文件:)更新了我的问题,希望这更简单。我所要做的就是在他们付钱后写下他们的名字和输入的内容我的服务器上的txt文件中的一行文本字段。好吧,我的ipn现在成功了,但是当我使用上面的脚本实际运行它时,它不会发送电子邮件或写入确实存在的文本文件。有什么想法吗?我想我很接近了,我只是没有看到它正常工作,在我的高级变量中,我有notify_url=,我也检查过它,它存在,但它不工作?你能告诉我们你是如何解决这个问题的吗?目前,这个答案并不能真正帮助其他可能有同样问题的人。如果你这么做了,我就打开你的问题。谢谢。对不起,这是一个老问题,当我是真正的新代码和网站,但是的,我记得下面的教程,并能够得到它连接和工作。主要的一点是在贝宝的网站上,你需要指向ipn脚本的按钮