You are here:Home»KB»Programming»PHP»Diagnose cURL connections
Sunday, 07 June 2015 11:41

Diagnose cURL connections

Written by

These following will help you diagnose cURL connections, if cURL is connects to the other end, SSL and how to enable cURL.

What is my cURL IP address?

This is not always as obvious as you think. If you are on a shared server and even if you have a dedicated IP address you are most likely still using the server's shared IP address. This can lead to a lot of confusion when diagnosing cURL connections issues and can still be preent on other variations of server i.e. VPS or dedicated but is more unlikely.

My script will allow you to find out what IP address your cURL service is using

Put this on your website that is having the paypal trouble. Put it in a file called curl-ip-test.php

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.myremotedomain.com/remote-ip-check.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
echo "Your Server's IP : ".$contents;
?>

Add this code to the remote website as a php file at www.myremotedomain.com/remote-ip-check.php

<?php
echo $_SERVER["REMOTE_ADDR"];
?>

Basically what these bits of code do, is that the remote script is accessed via the cURL service (from the server you are trying to work out the cURL IP address) and the remote script sees the IP that is being used and gives the cURL request that IP which is then displayed in your browser.

To get the IP just run the file via your web-browser ie www.mydomain.com/called curl-ip-test.php

How do i check if php server allows external curl connections

Create a file like this:

<?php 
phpinfo();
?>

or

<?php
echo "<pre>";
var_dump(curl_version());
?>

or

<?php
$var = echo shell_exec("/usr/bin/curl -L http://www.google.com");
?>

WHMCS Licensing Server Check Script

The following script is used to check to see if your WHMCS install can see the WHMCS.com licensing server. It also can be adapted to further test aspects of a cURL connection and is why I have added it here as a reference.

<?php

    $whmcsurl = "https://www.whmcs.com/index.php";
    $postfields = array("curltest"=>"1");

    $ip = gethostbyname('licensing28.whmcs.com');

    echo "<font style=\"font-size:18px;\">Testing Connection to '$whmcsurl'...<br />URL resolves to $ip<br /><br />";

    if ($ip!="184.94.192.3" && $ip!="208.74.120.227") echo "<font style=\"color:#cc0000;\">Error: The IP whmcs.com is resolving to the wrong IP. Someone on your server is trying to bypass licensing. You'll need your host to investigate and fix.</font><br /><br />";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $whmcsurl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);

	if (curl_error($ch)) {
		echo "Curl Error: ".curl_error($ch)."<br /><br />";
	} elseif (!$data) {
        echo "Empty Data Response - Please check CURL Installation<br /><br />";
    }

	curl_close($ch);
	
	echo "Connection Response (this should be the HTML from $whmcsurl when working correctly):<br /><br /><textarea rows=\"20\" cols=\"120\">$data</textarea>";

?>

Links

Read 1411 times Last modified on Sunday, 13 March 2016 13:51