Php PayPal重定向url不起作用

Php PayPal重定向url不起作用,php,paypal,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 * FR

我正在使用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>';


    }
    }
}
?>
但当我这么做,你付了钱或者你还了钱,它只会把你送到

而不是其他的。一定是这样


有什么办法可以解决这个问题吗?它可以正常工作,但我不希望这样。

您忽略了将输入另一个URL的值作为参数值进行正确的URL编码,因此,它将
&
视为“外部”URL中新参数的开始

在将
$generate\u url
值放入
$fullurl
值之前,在
$generate\u url
值上使用
rawurlencode
。(为了安全起见,您应该对所有参数值执行此操作。)

或者,让你的生活变得简单一点,并开始使用——它会自动为你处理必要的URL编码

$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);