gpt4 book ai didi

php - Paypal类文件错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:30:39 24 4
gpt4 key购买 nike

我的网站出现错误,这是错误消息“ fatal error :无法在第 123 行的 paypal.class.php 中重新分配自动全局变量 _POST”。它实际上是一个用于paypal 支付的类文件。我真的不知道如何解决这个问题,因为 paypal.class.php 文件只是下载的,我不是代码的作者。任何帮助将不胜感激。提前致谢! :)

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;">'."\n";

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

$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 .= "\n";
}

/* 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\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$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';
}
}}

最佳答案

您正在使用 $_POST 作为 doLog()checkPayment() 函数的参数,您不能使用 $_POST 作为函数/方法参数,将其更改为其他变量名称,例如:

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
}

并对您的 doLog() 函数进行类似的更改,例如 doLog($my_post);

关于php - Paypal类文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24426872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com