I write a form to send data to paypal and it works fine, I create a form with hidden fields, and then add a submit button that sends everything to paypal.
However, when the user clicks on this button, there is still something I want to do, for example, change the status of my basket in the database. This way, I want to be able to execute some code when they click the submit button, and then send the data to paypal.
I do not want to use javascript for this.
My method currently uses cURL, the form returns to the current page, then I check the $ _POST data, whether I execute my other commands, for example, update the state of the basket, and then create the curl command and send the form data message to PayPal. Now it receives the message successfully, but the browser does not go to paypal.
At first, I simply returned the result to a string, and then repeated it, and I could see that the message was successful, and then I set CURLOPT_FOLLOWLOCATION to 1, assuming that this would allow the browser to go to paypal, but that’s not what it seems, it’s grab some things from PayPal and put it on my page.
Does cURL use the right thing for this? and if so, how can I get around this? I want to stay away from javascript, since only users with javascript enabled would update their cart.
Below is the im code used for curl, post_data is the array I created and then read the key-value pairs in post_string.
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_MAXREDIRS, 20);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
curl_exec($curl_connection);