<?php
// Script to help locate PHP error logs and display recent errors

echo "<h2>PHP Error Log Diagnostic Tool</h2>";
echo "<hr>";

// 1. Check PHP error log settings
echo "<h3>1. PHP Error Log Configuration</h3>";
echo "<table border='1' cellpadding='5'>";
echo "<tr><th>Setting</th><th>Value</th></tr>";
echo "<tr><td>error_reporting</td><td>" . error_reporting() . "</td></tr>";
echo "<tr><td>display_errors</td><td>" . ini_get('display_errors') . "</td></tr>";
echo "<tr><td>log_errors</td><td>" . ini_get('log_errors') . "</td></tr>";
echo "<tr><td>error_log</td><td>" . (ini_get('error_log') ? ini_get('error_log') : 'Not set (using default)') . "</td></tr>";
echo "</table>";

echo "<hr>";

// 2. Common error log locations
echo "<h3>2. Common Error Log Locations to Check</h3>";
echo "<ul>";

$common_locations = [
    '/var/log/apache2/error.log',
    '/var/log/httpd/error_log',
    '/var/log/php_errors.log',
    '/var/log/php/error.log',
    __DIR__ . '/error_log',
    __DIR__ . '/php_errors.log',
    $_SERVER['DOCUMENT_ROOT'] . '/error_log',
    $_SERVER['DOCUMENT_ROOT'] . '/../logs/error_log',
];

foreach ($common_locations as $location) {
    $exists = file_exists($location) ? '<strong style="color:green;">EXISTS</strong>' : '<span style="color:gray;">Not found</span>';
    echo "<li>$location - $exists</li>";
}

echo "</ul>";

echo "<hr>";

// 3. Check for error_log files in current directory
echo "<h3>3. Error Log Files in Current Directory</h3>";
$files = glob(__DIR__ . '/*error*');
if (empty($files)) {
    echo "<p>No error log files found in current directory.</p>";
} else {
    echo "<ul>";
    foreach ($files as $file) {
        echo "<li>" . basename($file) . "</li>";
    }
    echo "</ul>";
}

echo "<hr>";

// 4. Try to trigger an error and see where it goes
echo "<h3>4. Test Error Logging</h3>";
error_log("TEST ERROR from find_error_logs.php at " . date('Y-m-d H:i:s'));
echo "<p>A test error has been logged. Check the error_log location above.</p>";

echo "<hr>";

// 5. cPanel error log location hint
echo "<h3>5. How to Find Error Logs in cPanel</h3>";
echo "<ol>";
echo "<li>Log into your cPanel account</li>";
echo "<li>Look for <strong>'Errors'</strong> or <strong>'Error Log'</strong> icon (usually in 'Metrics' or 'Logs' section)</li>";
echo "<li>Click on it to view PHP errors</li>";
echo "<li>OR go to <strong>File Manager</strong> → Look for 'error_log' file in your public_html or account root directory</li>";
echo "</ol>";

echo "<hr>";

// 6. Server information
echo "<h3>6. Server Information</h3>";
echo "<table border='1' cellpadding='5'>";
echo "<tr><td>Server Software</td><td>" . $_SERVER['SERVER_SOFTWARE'] . "</td></tr>";
echo "<tr><td>PHP Version</td><td>" . PHP_VERSION . "</td></tr>";
echo "<tr><td>Document Root</td><td>" . $_SERVER['DOCUMENT_ROOT'] . "</td></tr>";
echo "<tr><td>Script Filename</td><td>" . __FILE__ . "</td></tr>";
echo "</table>";

?>
