Sawtooth500
07-14-2009, 11:20 PM
So I have this nice and big form that collects data from users, the data is simply emailed. Also, when someone submits the form payment has to be submitted, and I'm just using one of those PayPal buy it now buttons. The code for the button is:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6803567">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Now I can't use that as my actual form code because there is much much more data I need to collect and if the action goes to paypal I won't get the data - so my form goes to an intermediate processing page and then that page needs to submit post data directly to paypal. That is where cURL comes in:
$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "cmd=_s-xclick&hosted_button_id=6803567");
curl_exec ($ch);
curl_close ($ch);
header("Location: https://www.paypal.com/cgi-bin/webscr");
As you can see from the paypal HTML code, there are only two POST fields that need to be sent. So I need cURL to redirect and send those two post fields. What is wrong with my PHP code for cURL? Right now it redirects to paypal, but goes to the paypal home page, which is what happens when that paypal URL gets typed in with no post values.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6803567">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Now I can't use that as my actual form code because there is much much more data I need to collect and if the action goes to paypal I won't get the data - so my form goes to an intermediate processing page and then that page needs to submit post data directly to paypal. That is where cURL comes in:
$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "cmd=_s-xclick&hosted_button_id=6803567");
curl_exec ($ch);
curl_close ($ch);
header("Location: https://www.paypal.com/cgi-bin/webscr");
As you can see from the paypal HTML code, there are only two POST fields that need to be sent. So I need cURL to redirect and send those two post fields. What is wrong with my PHP code for cURL? Right now it redirects to paypal, but goes to the paypal home page, which is what happens when that paypal URL gets typed in with no post values.