PHP POST to URL with user being redirected

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 04:59:07

问题


So I'm making a check out cart on my website. I'm using PayPal as the payment system but before I transfer the customers to PayPal I get their details. To do that I POST from index.php to index.php, run my code to retrieve the POSTed info and store it in a database and now wish to redirect the customer to PayPal.

Unfortunately you have to POST all the cart data to PayPal:

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

The only way I see around this is to post to index.php, collect the user data, then have a button show up saying click here to pay via PayPal. That's one extra step that I want to avoid.

Any way to POST to index.php, collect the data, then post the PayPal info to the PayPal website? Or any other ideas?

Thanks


回答1:


you would need 2 forms on your page, one form that posts back to index.php and a second form that posts to paypal

after the first form posts back to index.php, echo javascript in the body tag to submit the paypal form when it loads

    <?php
   if(isset($_POST['mydatafield'])){

        do database stuff

        $LOAD = 'document.paypal.submit();';
    }
    ?>
    <body onload="<?php echo $LOAD ?>">
    <form name="paypal" action="paypal.com?yadayada">
    paypal fields
    </form>
    <form name="myform" action="index.php">
    your form stuff
    submit button
    </form>



回答2:


You may fire submitting programmatically with JavaScript, eg:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypal_form">
...
<script type="text/javascript">
function submitPay(){
  document.getElementById("paypal_form").submit();
}
</script>



回答3:


You do not need to re-post your form from the client in the sense mentioned in other answers. You can instead use cURL to POST the data to PayPal and make it all look transparent to the user. Kinda like a forwarding of the posted form. You act on the data (save it, manipulate it or whatever) and forward the post to Paypal all in a single user transaction.

Here's a simple example: http://davidwalsh.name/execute-http-post-php-curl



来源:https://stackoverflow.com/questions/7426924/php-post-to-url-with-user-being-redirected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!