PHP停止脚本再次运行或删除变量或URL

时间:2015-05-04 10:07:25

标签: php paypal return

好的,不确定最好的方法。我已经通过这个网站做了一个serach但是找不到答案.....也许因为我不知道我在找什么。

基本上我使用Paypal自动返回页面,在该页面中,如果付款成功,将运行一个生成序列号的脚本。

但是,如果用户只是继续重新加载页面,他们将获得发送给他们的无限序列号,它永远不会结束。

如何阻止这种情况发生?事情是,一旦为用户创建了URL,他们就可以将该链接复制并粘贴到任何浏览器中,并且它将继续发送新的序列号。

我需要做什么?

由于

编辑:

这是我的完整代码:

    <?php
    $pp_hostname = "www.sandbox.paypal.com"; 

    $req = 'cmd=_notify-synch';

    $tx_token = $_GET['tx'];
    $auth_token = "tokencode";
    $req .= "&tx=$tx_token&at=$auth_token";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);

   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
    $res = curl_exec($ch);
    curl_close($ch);

    if(!$res){

    }else{

        $lines = explode("\n", $res);
        $keyarray = array();
        if (strcmp ($lines[0], "SUCCESS") == 0) {
            for ($i=1; $i<count($lines);$i++){
            list($key,$val) = explode("=", $lines[$i]);
            $keyarray[urldecode($key)] = urldecode($val);
            }

        $firstname = $keyarray['first_name'];
        $lastname = $keyarray['last_name'];
        $itemname = $keyarray['item_name'];
        $amount = $keyarray['payment_gross'];

        $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 = $keyarray['receiver_email'];
        $payer_email = $keyarray['payer_email'];
        //$businessemail = "contact@sample.com.au";

        echo ("<p><h3>Thank you for your purchase!</h3></p>");

        echo ("<b>Payment Details</b><br>\n");
        echo ("<li>Name: $firstname $lastname</li>\n");
        echo ("<li>Item: $itemname</li>\n");
        echo ("<li>Amount: $amount</li>\n");
        echo ("");

    echo "Thank you for your payment. Your transaction has been completed and a receipt for your purchase has been emailed to you.";
    echo $tx_token;



    $input = array("111", "222", "333");
    $filepath = ("Subscribe/" .  current($input) . ".txt");

    while (file_exists($filepath)) {
    $filepath = ("Subscribe/" . next($input) . ".txt");
    }

    $filepath = ("Subscribe/" . current($input) . ".txt");
    $SerialCurrent = current($input);
    $SerialEnd = end($input);

    $filepathlast = ("Subscribe/" . $SerialEnd . ".txt");

    if (file_exists($filepathlast)){//2nd If Start
        echo "No Serials Left";
    }
    else
    {
    $myfile = fopen($filepath, "w") or die("Unable to open file!");
    fwrite($myfile, $SerialCurrent);
    fclose($myfile);
    $filepath = ("Subscribe/" . reset($input) . ".txt");

        $gdate = date_default_timezone_set('Australia/Victoria');
        $DayIs = date("Y-m-d H:i e");

    mail($payer_email, "Subscription Details", "Thank you for subscribing. Please find your details below to register your software." . "\nSerial Number : " . $SerialCurrent . "\nProduct : " . $item_name . "\nDate : " . $DayIs);

    mail($receiver_email, "Subscription Details", "WindowCAD Subscribe" . "\nSerial Number : " . $SerialCurrent . "\nProduct : " . $item_name . "\nDate : " . $DayIs);
    }
       }
        else if (strcmp ($lines[0], "FAIL") == 0) {
          echo "Oh no - Error;";
        }
    }

    ?>


    Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br> You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>

1 个答案:

答案 0 :(得分:0)

在重新生成并发送(新)序列号之前,如果已经为该客户发送了该事务的序列号,则进行检查(db),如果是,则不生成/发送,如果没有,则发送,并将其记录在发送的数据库中......

如果没有任何具体的例子,我们可能无法提供进一步的帮助。