How can I send users to PayPal after some processing on the server. {PHP}
I am setting up a paid subscription service and want to keep the signup form to one 开发者_运维百科page. I use PayPal as my payment processor and the standard way of dealing with paypal is to create "Buttons" that POST to PayPal.
However, I need to process the form data before I send the user to paypal. Once I have processed the data, how would I redirect the user to paypal from the server?
Thanks
Since you must use POST, the best method may be to add a bit of javascript to auto-submit the form to a page that you send users to on your site after they complete the rest of the registration process. Make sure you include checks to ensure that the rest of the registration was valid before you show the code. So it would be something like this:
<?php
if (checkRegistration()) {
?>
<html><head><title>Registration Checkpoint</title>
<script type="text/javascript">
window.onload = function () {
var form = document.getElementById("PDFGenerationForm");
form.submit();
};
function OnFormSubmit() {
alert("Submitting form.");
}
</script>
</head><body></body></html>
<?
}
?>
Assuming you have the exact URL on paypal to which you will send them, stored in the variable $url, adding this line after the processing should do the trick:
header("Location: ".$url);
For more info on the header function, check out the description in the php manual: http://php.net/manual/en/function.header.php
精彩评论