PayPal重定向网址不起作用

时间:2015-10-17 12:02:14

标签: php paypal

我使用PayPal让我的网站工作,我遇到了问题

这是我的代码,让我解释一下我想要什么和什么不起作用。

<?php
if($_GET['action'] == 'payment_out') //Check from URL if a invoice is going to be payed.
{

    $dbh = new PDO('xxx'); //Connect to the database
    $gpi = $dbh->prepare("SELECT * FROM invoice WHERE invoice_id = ('{$_GET['id']}')"); //Prepare the statement
    $gpi->execute(); //Execute statement
    while ($row = $gpi->fetch(PDO::FETCH_ASSOC)) //Create all needed variables
    {
        $iid = $row['invoice_id'];
        $iow = $row['invoice_owner'];
        $iit = $row['invoice_item'];
        $ipr = $row['invoice_price'];
        $ipp = $row['invoice_payprice'];
        $ist = $row['invoice_status'];
        $ispk = $row['invoice_spk'];
    }
    if($_SESSION['user_name'] == $iow)
    {
    $method = $_GET['method']; //Get the method
    $payment_start = $iow . ' started paying invoice #'.$iid; //Log that the payment started
    $payment_cancel = $method . ' cancelled payment for invoice #'.$iid; //Log that the payment got cancelled
    $ps = $dbh->prepare("INSERT INTO logs (invoice_id,log_exby,log_action,log_time) VALUES ('$iid','$iow','$payment_start',NOW())"); //Prepare the statement
    $ps->execute(); //Insert into logs
    if($_GET['method'] == 'paypal') //Check the payment
    {
        echo '<div class="alert alert-success alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        <h4><i class="fa fa-check-circle"></i> Please wait...</h4> Sending you to PayPal, please wait.
        </div>'; //Tell user that paying is disabled.
                $cancel_return = 'http://x/ClientArea/base_pages_upgrade.php?action=payment_cancel&amp;id='. $iid .'&method=PayPal';
        $return = 'http://x/ClientArea/base_pages_upgrade.php?action=complete_payment&amp;id='. $iid .'&secret_code=' . $ispk . '&method=PayPal&item='. $iit;

        echo '<script>
window.onload = function(){
  document.forms["pay"].submit()

}
</script>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="pay">
  <input type="hidden" name="cmd" value="_xclick" />
  <input type="hidden" name="business" value="x" />
  <input type="hidden" name="quantity" value="1" />
  <input type="hidden" name="item_name" value="'. $iit .'" />
  <input type="hidden" name="item_number" value="Order_'. $iid .'" />
  <input type="hidden" name="amount" value="0.01" />
  <input type="hidden" name="shipping" value="0.00" />
  <input type="hidden" name="no_shipping" value="1" />
  <input type="hidden" name="cn" value="Comments" />
  <input type="hidden" name="currency_code" value="USD" />
  <input type="hidden" name="lc" value="US" />
  <input type="hidden" name="bn" value="PP-BuyNowBF" />
  <input type="hidden" name="return" value="'. $return . '" />
  <input type="hidden" name="cancel_return" value="'. $cancel_return . '" /> 
  <input type="hidden" name="image_url" value="http://i.imgur.com/oxtw9XW.png" />
</form>';


    }
    }
}
?>

这就是我目前正在使用的内容,但我不想这样,我想使用这个

$generate_url = 'cmd=_xclick&business=x&quantity=1&item_name=' . $iit . '&item_number='. $iid . '&amount=0.01&no_shipping=1&cn=Comments&currency_code=USD&lc=US&image_url=http://i.imgur.com/oxtw9XW.png';
$fullurl = 'http://paypal.com/cgi-bin/webscr?'. $generate_url .'&return='.$return.'&cancel_return='.$cancel_return;
        header('Location: '.$fullurl);

但是当我这样做而且你支付了或者你退回时它只是送你去

  

http://website.com/ClientArea/base_pages_upgrade.php?action=complete_payment

而不是其余的。它必须是

  

http://website.com/ClientArea/base_pages_upgrade.php?action=complete_payment&id=ID&secret_code=CODE&item=ITEM

有什么办法可以解决这个问题吗?它有效,但形式但我不想这样。

1 个答案:

答案 0 :(得分:0)

您忽略了对放入另一个网址的值进行正确的URL编码作为参数值 - 因此,它将&视为新参数的开头“外部”网址。

在将rawurlencode值添加到$generate_url之前,使用$fullurl。 (并且您应该在所有参数值上执行此操作,以确保安全。)

或者,让您的生活更轻松,并开始使用http_build_query - 它会自动为您处理必要的网址编码。