Jump to content
iwato

Using cURL Across Different Domains in the Same Domain File Structure

Recommended Posts

BACKGROUND:  My jubilation was short-lived.  For the internal server error that was plaguing my site in general is now plaguing a crucial file in particular.  Please find below a file that works perfectly well on my local test server, but fails with an internal server error on my host server.  Please also note that the file matomo/index.php is located on the same server as that from which the cURL call is made, but under a different domain name.

ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');
ini_set('html_errors', 0);
ini_set('display_errors', 0);
error_reporting(E_ALL);
$url = 'https://.../matomo/index.php?module=API&method=API.getIpFromHeader&format=JSON&token_auth=...';
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, false);
curl_exec($curl_request);
curl_close($curl_request);

 

QUESTION:  Does cURL not work in such an environment?  If it does, then what must I do to make it work?  The error.log file contains nothing and the AJAX that made the call does not complain of not being able to access the file.

Roddy

Edited by iwato

Share this post


Link to post
Share on other sites

You can do testing by typing the URL of the PHP script in your browser instead of using AJAX. This way you can easily see what's being printed to the screen. curl_exec() returns a boolean value, you should check to see if it's false, and if so then you can use curl_error() to see why it failed.

Share this post


Link to post
Share on other sites

I do not know how to modify the code in the file with my browser.  I can see how to modify the request headers, but this is all.  In the meantime I inserted the following code between the cURL exec statement and the cURL close statement.  Still nothing appeared in the error.log file.

Thank you for reminding about the curl_error() statement.  I had long since forgotten.  The last time I used cURL outside of terminal was way back in 2010 when I was still in Thailand teaching myself PHP with the help of W3Schools.

if(curl_errno($curl_request)) {
    echo 'Curl error: ' . curl_error($curl_request);
}

I have resent my initial query to my host server, as I believe it got lost in their desire to put their own house in order.  Also, adding the curl_errno() and curl_error() functions reveal no new information.  Apparently, nothing is able to get pass the persistent internal server error.

Roddy

Edited by iwato

Share this post


Link to post
Share on other sites

OK.  My host server has replied.  JSG was correct.  The permissions of the file in question had been set to 664, rather than 644, thus giving write permissions to group.  In the discovery process I have also learned how to discover and set the file permissions on documents residing on my host server  so that the problem can be easily resolved in the future.

Roddy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×