How to use PHP CURL to bypass cross domain

穿精又带淫゛_ 提交于 2019-12-20 03:33:11

问题


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


回答1:


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);



回答2:


Using false in CURLOPT_RETURNTRANSFER doesn't return anything by curl. make it true(or 1)

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


来源:https://stackoverflow.com/questions/22676866/how-to-use-php-curl-to-bypass-cross-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!