Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
paypal通知php脚本的url操作不断重复_Php_Paypal_Wordpress - Fatal编程技术网

paypal通知php脚本的url操作不断重复

paypal通知php脚本的url操作不断重复,php,paypal,wordpress,Php,Paypal,Wordpress,我有一个小动作脚本,当有人用Paypal买东西时我会运行它 Using the notify_url=http://www.mysite.com/my-automatic-script.php 我正在使用网站上的mail()功能自动获取电子邮件地址并用一些信息更新用户 一切都很完美,但脚本只是不断地重复。(我每5分钟收到一封电子邮件,上面写着这个) 此处的脚本: require('wp-blog-header.php'); $user_email = trim(isset($_POST['

我有一个小动作脚本,当有人用Paypal买东西时我会运行它

Using the notify_url=http://www.mysite.com/my-automatic-script.php
我正在使用网站上的mail()功能自动获取电子邮件地址并用一些信息更新用户

一切都很完美,但脚本只是不断地重复。(我每5分钟收到一封电子邮件,上面写着这个)

此处的脚本:

require('wp-blog-header.php');


$user_email = trim(isset($_POST['payer_email']) ? $_POST['payer_email'] : "");
$us_firstname = trim(isset($_POST['first_name']) ? $_POST['first_name'] : "");
$us_lastname = trim(isset($_POST['last_name']) ? $_POST['last_name'] : "");

$randomkey = rand(0, 9999);
$user_name = $us_lastname . '_' . $randomkey; 

$user_id = email_exists( $user_email );
if ( !$user_id ) {
    $random_password = wp_generate_password ( 12, false, false );

    $user_id = wp_create_user( $user_name, $random_password, $user_email );


    wp_update_user( array ('ID' => $user_id, 'first_name' => $us_firstname, 'last_name' => $us_lastname) ) ;

    update_user_meta( $user_id, 'subscription_status', 'subscribed' );
    update_user_meta( $user_id, 'subscription_level', '3' );
    update_user_meta( $user_id, 'subscription_pack', 'Manual' );
    update_user_meta( $user_id, 'subscription_key', '' );
    update_user_meta( $user_id, 'subscription_expires', date('Ymd', strtotime('+ 365 day')) );




// The message
$headers = "From: no-reply@mysite.com";

$message2 = "Here is my message";
// Send
mail($user_email, 'Welcome to my site', $message2, $headers);


  //end mail



break;  



} else {
    $headers = "From: no-reply@mysite.com";

$message2 = "This user is already registered";
mail('me@me.com', 'Purchase from Registered User', $message2, $headers);
}

break;
提前谢谢!是休息;够了吗

另一更新:

我选择了PDT PayPal路线:

看来这是可行的

$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];
$auth_token = "my-secret-code";
$req .= "&tx=$tx_token&at=$auth_token";

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines = explode("\n", $res);
$keyarray = array();

这个问题令人费解,您的示例是某种伪代码。你能发布实际代码吗?另外,首先确定是什么导致它被多次调用:paypal是否多次调用url?(过程中是否调用了cron作业?)您的示例代码实际上来自my-automatic-script.php还是其他地方?你可以发布一个链接到整个文件吗?我怀疑PayPal每5分钟就会点击一次你的通知URL。正如加藤所说,提供实际的代码,如果涉及到cron作业。实际上,PayPal well可能会反复点击您的通知URL。如果您的脚本没有返回正确的HTTP/1.1 200 OK响应,它将在每个IPN消息中重新尝试IPN传递多达16次。修复它的最简单方法(除了找出它为什么不返回200响应之外)是在脚本的开头添加一个header()字段来发送它。例如,
标题(“HTTP/1.1200ok”)尝试添加退出;就在邮件发送之后。在这种情况下,我很少帮助过我。。