<?php
$logFile = __DIR__ . '/debug_log.txt';
if (file_exists($logFile)) {
    echo "<h1>Log File (Newest First)</h1>";
    echo "<a href='?clear=1'>Clear Log</a><br><br>";
    
    if (isset($_GET['clear'])) {
        file_put_contents($logFile, "Log cleared at " . date('Y-m-d H:i:s') . "\n");
        header("Location: view_log.php");
        exit;
    }
    
    $lines = file($logFile);
    $lines = array_reverse($lines);
    echo "<pre>";
    foreach ($lines as $line) {
        echo htmlspecialchars($line);
    }
    echo "</pre>";
} else {
    echo "Log file not found at: " . $logFile;
}
