Jump to content

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


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.


Edited by iwato
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.

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.


Edited by iwato
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.


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...