Get errorlog with php script

Dirgni

New member
Joined
Dec 24, 2025
Messages
2
I have a function that I use to get the errorlog from the DirectAdmin errorlog. This worked fine for several years. Now my application is moved to another server with a newer version of DirectAdmin and my script doesn't return the any result, although I see the errorlog isn't empty. Should there be changed something or is there a better way to get the errorlog?

PHP:
<?php
    function getErrorlog($sServer, $sPort, $sUsername, $sPassword, $sDomain, $sSubdomain) {
        // get the errorlog from direct admin
        $url = 'https://' . $sServer . ':' . $sPort;
        $ckfile = tempnam ('/tmp', 'CURLCOOKIE');
        $fields = array(
            'referer' => urlencode('/'),
            'username' => urlencode($sUsername),
            'password' => urlencode($sPassword)
        );
        $fields_string = '';
        foreach($fields as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        rtrim($fields_string, '&');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL, $url . '/CMD_LOGIN');
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer: ' . $url . '/CMD_LOGIN'));
        $result = curl_exec($ch);
        if($result === false) {
            die('CURL ERROR: ' . curl_error($ch));
        }
        else {
            curl_setopt($ch, CURLOPT_URL, $url . '/CMD_SHOW_LOG?domain=' . $sDomain . '&type=error&subdomain=' . $sSubdomain);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec($ch);
            curl_close($ch);
            if($result === false) {
                die('CURL ERROR: ' . curl_error($ch));
            }
            else {
                $aLines = explode(PHP_EOL, $result);
                $sResult = '';
                foreach ($aLines as $line) {
                    if ($line != '') {
                        $iPosCertificate = strpos($line, 'server certificate does NOT include an ID which matches the server name');
                        $iPosEnv = strpos($line, '/.env');
                        $iPosStatus = strpos($line, '/server-status');                     
                        if ($iPosCertificate == 0 && $iPosEnv == 0 && $iPosStatus == 0) {
                            $sResult .= $line . PHP_EOL . PHP_EOL;
                        }
                    }
                }
                return $sResult;
            }
        }
    }
?>
 
Hello,

What error do you get when running the function on a new server?

You might temporary change the lines

PHP:
$result = curl_exec($ch);

to

PHP:
$result = curl_exec($ch);
var_dump($result);

to see output from API calls.
 
Hello,

What error do you get when running the function on a new server?

You might temporary change the lines

PHP:
$result = curl_exec($ch);

to

PHP:
$result = curl_exec($ch);
var_dump($result);

to see output from API calls.
I get no error, I just get no result.
 
dump: curl_getinfo , curl_error , curl_exec
or try to use the real API call
 
Back
Top