簡體   English   中英

貝寶重定向網址不起作用

[英]PayPal redirect url does not work

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

有什么辦法可以解決這個問題? 它可以工作,但是形式,但是我不想要。

您已經忽略了將輸入到另一個 URL中的值正確地URL編碼為參數值的方法–因此,它將&視為“外部” URL中新參數的開始。

使用rawurlencode$generate_url價值,你把它放到前$fullurl值。 (為了安全起見,應該對所有參數值執行此操作。)

或者,讓您的生活更輕松一些,並使用http_build_query開始–它會自動為您處理必要的URL編碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM