douxiji8707 2014-06-26 09:25
浏览 56
已采纳

Paypal类文件错误

I'm having a problem with an error on my website, here's the error message "Fatal error: Cannot re-assign auto-global variable _POST in paypal.class.php on line 123". It's actually a class file for paypal payments. I really have no idea on how to solve this as the paypal.class.php file is only downloaded and I am not the author of the code. Any help would be very much appreciated. Thanks in advance! :)

class Paypal {

private $VARS;
private $button;
private $logFile;
private $isTest=false;

/* Print Form as Link */
function getLink()
{
    $url = $this->getPaypal();
    $link = 'https://'.$url.'/cgi-bin/webscr?';
    foreach($this->VARS as $item => $sub){
        $link .= $sub[0].'='.$sub[1].'&';
    }
    return $link;
}

/* Print Form */
function showForm()
{
    $url = $this->getPaypal();
    $FORM  = '<form action="https://'.$url.'/cgi-bin/webscr" method="post" target="_blank" style="display:inline;">'."
";

    foreach($this->VARS as $item => $sub){
        $FORM .= '<input type="hidden" name="'.$sub[0].'" value="'.$sub[1].'">'."
";
    }

    $FORM .= $this->button;    
    $FORM .= '</form>';
    echo $FORM;
}

/* Add variable to form */
function addVar($varName,$value)
{
    $this->VARS[${varName}][0] = $varName;
    $this->VARS[${varName}][1] = $value;
}

/* Add button Image */
function addButton($type,$image = NULL)
{
    switch($type)
    {
        /* Buy now */
        case 1:
            $this->button = '<input type="image" height="21" style="width:86;border:0px;"';
            $this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" ';
            $this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
            break;
        /* Add to cart */   
        case 2:
            $this->button = '<input type="image" height="26" style="width:120;border:0px;"';
            $this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit"';
            $this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
            break;
        /* Donate */    
        case 3:
            $this->button = '<input type="image" height="47" style="width:122;border:0px;"';
            $this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit"';
            $this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
            break;
        /* Gift Certificate */
        case 4: 
            $this->button = '<input type="image" height="47" style="width:179;border:0px;"';
            $this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_giftCC_LG.gif" border="0" name="submit"';
            $this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
            break;
        /* Subscribe */
        case 5: 
            $this->button = '<input type="image" height="47" style="width:122;border:0px;"';
            $this->button .= 'src="https://www.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit"';
            $this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
            break;
        /* Custom Button */
        default:
            $this->button = '<input type="image" src="'.$image.'" border="0" name="submit"';
            $this->button .= 'alt="PayPal - The safer, easier way to pay online!">';
    }
    $this->button .= "
";
}

/* Set log file for invalid requests */
function setLogFile($logFile)
{
    $this->logFile = $logFile;
}

/* Helper function to actually write to logfile */
private function doLog($_POST)
{
    ob_start();
    echo '<pre>'; print_r($_POST); echo '</pre>';
    $logInfo = ob_get_contents();
    ob_end_clean();

    $file = fopen($this->logFile,'a');
    fwrite($file,$logInfo);
    fclose($file);
}

/* Check payment */
function checkPayment($_POST)
{
    /* read the post from PayPal system and add 'cmd' */
    $req = 'cmd=_notify-validate';

    /* Get post values and store them in req */
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }

    $url = $this->getPaypal();

    /* post back to PayPal system to validate */
    $header .= "POST /cgi-bin/webscr HTTP/1.0
";
    $header .= "Content-Type: application/x-www-form-urlencoded
";
    $header .= "Content-Length: " . strlen($req) . "

";
    $fp = fsockopen ('ssl://'.$url, 443, $errno, $errstr, 30);

    /*
    If ssl access gives you problem. try regular port:
    $fp = fsockopen ($url, 80, $errno, $errstr, 30);
    */

    if (!$fp) {
        /* HTTP ERROR */
        return false;
    } else {
        fputs ($fp, $header . $req);
        while (!feof($fp)) {
            $res = fgets ($fp, 1024);
            if (strcmp ($res, "VERIFIED") == 0) {

                return true;
            } else {
            if (strcmp ($res, "INVALID") == 0) {
                /*
                log for manual investigation
                */
                if($this->logFile != NULL){
                    $this->doLog($_POST);
                }
                return false;
            }
        }
        fclose ($fp);
    }
    return false;
}

/* Set Test */
function useSandBox($value)
{
    $this->isTest=$value;
}

/* Private function to get paypal url */
private function getPaypal()
{
    if($this->isTest == true){
        return 'www.sandbox.paypal.com';
    } else {
        return 'www.paypal.com';
    }
}}
  • 写回答

1条回答 默认 最新

  • doushi6947 2014-07-01 03:01
    关注

    you are using $_POST as argument to doLog() and checkPayment() function, you cannot use $_POST as a function / method argument, change that to some other variable name, like:

    function checkPayment($my_post)
    {
        /* read the post from PayPal system and add 'cmd' */
        $req = 'cmd=_notify-validate';
    
        /* Get post values and store them in req */
        foreach ($my_post as $key => $value) {
            $value = urlencode(stripslashes($value));
            $req .= "&$key=$value";
        }
        //rest of your code
    }
    

    and make similar change to your doLog() function, like doLog($my_post);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决