代码之家  ›  专栏  ›  技术社区  ›  Accountant Ù

通过重定向客户端通过“GET”而不是“POST”发送PayPal表单

  •  1
  • Accountant Ù  · 技术社区  · 9 年前

    POST是PayPal发送PayPal按钮的推荐方法 documentations . 他们明确指出:

    <FORM action="https://www.paypal.com/cgi-bin/webscr" method="post">

    重要提示:不要更改这些值。这些属性是必需的 对于所有付款按钮和购物车上载命令

    但是在 this tutorial ,作者正在服务器端构建按钮变量,然后将客户端重定向到PayPal,这将使请求通过“GET”而不是“POST”转到PayPal。某物 喜欢 这

    <form class="paypal" action="/payments.php" method="post">
        <select name="product">
            <option value="A">A</option>
            <option value="B">B</option>
        </select>
        <input name="discountCode" type="text">
        <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!">
    </form>
    

    然后,他在服务器上构建了PayPal变量,并将客户端重定向到PayPal继续

    付款。php

    $paypal_email = 'user@example.com';
    $return_url = 'http://example.com/payment-successful.html';
    $cancel_url = 'http://example.com/payment-cancelled.html';
    $notify_url = 'http://example.com/payments.php';//same file
    $item_name = 'Test Item'; //build the item and amount depend on what is selected in the form
    $item_amount = 5.00;
    
    $querystring = '';
    $querystring .= "?business=".urlencode($paypal_email)."&";
    $querystring .= "cmd=_xclick&";
    $querystring .= "item_name=".urlencode($item_name)."&";
    $querystring .= "amount=".urlencode($item_amount)."&";
    $querystring .= "return=".urlencode(stripslashes($return_url))."&";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
    $querystring .= "notify_url=".urlencode($notify_url);
    
    // Redirect to paypal (will cause GET request to PayPal)
    header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
    exit();
    

    <form> 但是,客户仍然可以看到他被引导到哪里 ).

    在服务器端构建PayPal变量,然后通过GET请求将客户端重定向到PayPal是否可靠并受支持?

    3 回复  |  直到 9 年前
        1
  •  2
  •   Peon    9 年前

    并不是说这是最好的选择,但要创建帖子表单,您可以编辑您的 付款。php 具体如下:

    <?php
    
    $paypal_email = 'user@example.com';
    $return_url   = 'http://example.com/payment-successful.html';
    $cancel_url   = 'http://example.com/payment-cancelled.html';
    $notify_url   = 'http://example.com/payments.php';//same file
    $item_name    = 'Test Item'; //build the item and amount depend on what is selected in the form
    $item_amount  = 5.00;
    
    $querystring = [
        'business'      => urlencode($paypal_email),
        'cmd'           => '_xclick',
        'item_name'     => urlencode($item_name),
        'amount'        => urlencode($item_amount),
        'return'        => urlencode(stripslashes($return_url)),
        'cancel_return' => urlencode(stripslashes($cancel_url)),
        'notify_url'    => urlencode($notify_url),
    ];
    
    ?>
    
    <html>
    <head>
    </head>
    <body>
        <form id="myForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
            <?php
            foreach ($querystring as $a => $b) {
                echo "<input type='hidden' name='".htmlentities($a)."' value='".htmlentities($b)."' />";
            }
            ?>
        </form>
        <script type="text/javascript">
            document.getElementById('myForm').submit();
        </script>
    </body>
    </html>
    <?php
    exit();
    
        2
  •  1
  •   Radderz    7 年前

    HTTP 414 URI太长

    当你开始包括多个产品、名称、价格、服务器令牌、地址等时,这种规模很快就会增加。就我个人而言,我曾看到在使用单个产品和最少数据的情况下超过了这一限制,因此出于跨浏览器兼容性目的,使用POST更安全。

        3
  •  0
  •   Craig    7 年前

    在我看来,无论你是使用自动提交的javascript还是头并将字段发送到paypal,这都无关紧要。重要的是,你发送给paypal的内容不应该出现在隐藏字段中,表格上写着“立即点击付款”,即不自动提交,否则用户可以在浏览器调试模式下读取这些隐藏字段。我将这些编码的变量作为会话变量从页面(a)传递到单独的发送页面(B),在(B)中解开代码,生成一个传递令牌到paypal,并对(B)进行大量冗余检查,例如页面中止,如果不是来自(a),则所有会话变量都在那里并与其未编码的对应项匹配。返回发送到paypal的传递生成的令牌字段,因此可以将其与编码的会话对应项进行比较以验证paypal,尽管您可以卷曲到paypal以检查其合法性。你必须以闪电般的速度单独在(B)上停止浏览器,理论上你可以阅读这两篇文章并到达那里,但不等待用户输入是一个巨大的威慑安全智慧,你必须复制大量冗余的检查变量。

    推荐文章