Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PHP CURL to bypass cross domain

I need PHP to submit paramaters from one domain to another. JavaScript is not an option for my situation. I'm now trying to use CURL with PHP, but have not been successful in bypassing the cross domain.

From domain_A, I have a page with the following PHP with CURL script:

if (_iscurl()){
    echo "<p>CURL is enabled</p>";
    $url = "http://domain_B/process.php?id=123&amt=100&jsonp=?";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt($ch, CURLOPT_URL, $url );
    $return = curl_exec($ch);
    curl_close($ch);

    echo "<p>Finished operations</p>";
}
else{
    echo "CURL is disabled";
}
?>

I am not getting any results, so I am assuming that the PHP CURL script is not successful. Any ideas to fix this?

Thanks

like image 929
Jun Dolor Avatar asked Dec 13 '25 23:12

Jun Dolor


1 Answers

Well, its bit late. But adding this answer for further readers who might face similar issue. This issue arises some times when we are sending php curl request from a domain hosted over http to a domain hosted over https (http over ssl).

Just add below code snippet before curl execution.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
like image 126
Nagama Inamdar Avatar answered Dec 15 '25 12:12

Nagama Inamdar