2

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

Jun Dolor
  • 609
  • 2
  • 11
  • 25

2 Answers2

10

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);
Nagama Inamdar
  • 2,851
  • 22
  • 39
  • 48
1

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

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
  • Hi, the parameter has been set to true, i.e. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); but I'm still getting the same results. Could it be that there's a port blocking the call? – Jun Dolor Mar 28 '14 at 03:52
  • I've included an error tracking: if(curl_errno($ch)) { echo 'error#:' . curl_errno($ch) . '/ error:' . curl_error($ch); } I got error#7, unable to connect to host. However, our admin advised me that all ports are open and therefore no firewall is applied – Jun Dolor Mar 28 '14 at 07:32
  • Please update your code if you used `true` for return-transfer. Also, add this to your curl `curl_setopt($ch, CURLOPT_VERBOSE, true);` and it will generate some output. Show that output to me. – Sabuj Hassan Mar 28 '14 at 12:03
  • Hi,the return-transfer is set to true and I've added `curl_setopt($ch, CURLOPT_VERBOSE, true);`. I've used `print CURLOPT_VERBOSE;`. I'm getting a value of 41. I'm now checking what the value means – Jun Dolor Mar 31 '14 at 02:09
  • The URL I'm trying to call is published on port 1337. I was wondering if this is the root of the problem? Maybe this should be set at port 80? – Jun Dolor Mar 31 '14 at 02:57
  • If you can browse it from browser, then curl should do it. However try to set the port through this option `curl_setopt($ch, CURLOPT_PORT, 1337);`. I never used it, doing experiment on you :D – Sabuj Hassan Mar 31 '14 at 06:44
  • Hi, just tried out `curl_setopt($ch, CURLOPT_PORT, 1337);` but still getting the same results. I really think there's something in our server that's blocking PHP+CURL call. – Jun Dolor Apr 02 '14 at 05:12
  • Is there any chance to get the actual url? Disguised under tinyurl will do? Otherwise everything is blackbox to me :( – Sabuj Hassan Apr 02 '14 at 07:11
  • Hi, I'm afraid that I'm not at liberty to divulge the url, even in tinyurl format :-) But here's the weird part, if I reverse the process- before it was domain A submitting parameters to domain B via PHP Curl, and now its domain B submitting parameters to domain A via PHP Curl using the same script, the whole process works. It must be a server issue, but the question now is- what issue is it? – Jun Dolor Apr 03 '14 at 08:46