I'm developing a form in which requires to submit the collected data to a third party website, in the form of: http://www.domain.com/page?key=value&key2=value2
I decide to use cURL as I have not found an alternative that convince me.
The problem that I'm running is that once the form is submitted, cURL is executed but I'm being redirected to the domain that I specified. Instead, I want to redirect the user to a confirmation page within my domain and not to the third party website.
Here is an example of the code that I'm using:
$URL="otherserver.domain.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "key=value2&key2=value2&key3=value3");
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close ($ch);
How can I prevent from being redirected to otherserver.domain.com?
Please feel free to let me know if you think that instead of using cURL, there is a better way to submit the data to the third party website.
Thank you all in advance
Try this:
<?php
$url = "http://***..";
$ch = curl_init($url);
$opts = array(CURLOPT_RETURNTRANSFER => 1,
CURLOP_HEADER => 1,
CURLOPT_FOLLOWLOCATION => 0,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => "foo=ba");
curl_setopt_array($ch, $opts);
echo curl_exec($ch);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With