fix this codes and change to be good and (<?php
// index.php

// Error reporting for debugging (remove in production)
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Function to log messages
function logMessage($message) {
    $logFile = 'change_detector.log';
    $timestamp = date('Y-m-d H:i:s');
    file_put_contents($logFile, "[$timestamp] $message\n", FILE_APPEND);
}

// Function to get the last check time from the log
function getLastCheckTime() {
    $logFile = 'change_detector.log';
    if (file_exists($logFile)) {
        $lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        if (!empty($lines)) {
            $lastLine = end($lines);
            preg_match('/$(.*?)$/', $lastLine, $matches);
            if (isset($matches[1])) {
                return $matches[1];
            }
        }
    }
    return 'Never';
}

// Function to check for changes on the page
function checkForChanges($url) {
    // Initialize cURL session
    $ch = curl_init();

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');

    // Execute cURL request and get the response
    $response = curl_exec($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        logMessage("cURL Error: " . curl_error($ch));
        return ['error' => 'Error: ' . curl_error($ch)];
    }

    // Close cURL session
    curl_close($ch);

    // Generate a hash of the entire page content
    $currentHash = md5($response);

    // Compare with previous hash
    $previousHash = '';
    if (file_exists('previous_hash.txt')) {
        $previousHash = file_get_contents('previous_hash.txt');
    }

    if ($currentHash !== $previousHash) {
        // Save the new hash
        file_put_contents('previous_hash.txt', $currentHash);

        logMessage("Changes detected. New hash: " . $currentHash);

        return [
            'changed' => true,
            'oldHash' => $previousHash,
            'newHash' => $currentHash
        ];
    }

    logMessage("No changes detected");
    return ['changed' => false];
}

// Main code
$url = 'https://longevacare.com/the-longeva-concept/';
$lastCheckTime = getLastCheckTime();
$changeStatus = 'No changes detected';
$hashInfo = '';
$changesDetected = false;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['check_status'])) {
    try {
        $result = checkForChanges($url);
        $lastCheckTime = date('Y-m-d H:i:s');
        
        if (isset($result['error'])) {
            $changeStatus = $result['error'];
            logMessage("Error occurred: " . $result['error']);
        } elseif ($result['changed']) {
            $changeStatus = 'Changes detected!';
            $hashInfo = "Old Hash: " . substr($result['oldHash'], 0, 8) . "...<br>New Hash: " . substr($result['newHash'], 0, 8) . "...";
            logMessage("Changes detected on the page");
            $changesDetected = true;
        } else {
            $changeStatus = 'No changes detected';
            logMessage("No changes detected on the page");
            $changesDetected = false;
        }
    } catch (Exception $e) {
        $changeStatus = 'Error: ' . $e->getMessage();
        logMessage("Exception occurred: " . $e->getMessage());
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Longeva Care Page Change Detector</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Roboto', sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f0f0f0;
            color: #333;
        }
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
        }
        .container {
            background-color: #ffffff;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .status {
            font-size: 24px;
            font-weight: bold;
            margin: 20px 0;
            text-align: center;
            padding: 15px;
            border-radius: 5px;
        }
        .changes {
            background-color: #e74c3c;
            color: white;
        }
        .no-changes {
            background-color: #2ecc71;
            color: white;
        }
        .error {
            background-color: #f39c12;
            color: white;
        }
        .last-check {
            font-style: italic;
            color: #7f8c8d;
            text-align: center;
            margin-bottom: 20px;
        }
        form {
            text-align: center;
            margin-top: 30px;
        }
        button {
            padding: 12px 24px;
            font-size: 16px;
            cursor: pointer;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #2980b9;
        }
        .hash-info {
            margin-top: 20px;
            border: 1px solid #bdc3c7;
            padding: 15px;
            font-family: monospace;
            background-color: #ecf0f1;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Longeva Care Page Change Detector</h1>
        <div id="statusContainer" class="status <?php echo strtolower(str_replace(' ', '-', $changeStatus)); ?>">
            <?php echo $changeStatus; ?>
        </div>
        <div id="lastCheckContainer" class="last-check">
            Last checked: <?php echo $lastCheckTime; ?>
        </div>
        <form id="checkForm" method="post">
            <button type="submit" name="check_status">Check for Changes Now</button>
        </form>

        <div id="hashInfoContainer" class="hash-info" style="display: <?php echo !empty($hashInfo) ? 'block' : 'none'; ?>">
            <h2>Hash Information:</h2>
            <div id="hashInfoContent"><?php echo $hashInfo; ?></div>
        </div>
    </div>

    <audio id="alarmAudio" loop>
        <source src="alarm_1.mp3" type="audio/mpeg">
        Your browser does not support the audio element.
    </audio>

    <script>
    document.addEventListener('DOMContentLoaded', function() {
        var audio = document.getElementById('alarmAudio');
        var checkForm = document.getElementById('checkForm');
        var statusContainer = document.getElementById('statusContainer');
        var lastCheckContainer = document.getElementById('lastCheckContainer');
        var hashInfoContainer = document.getElementById('hashInfoContainer');
        var hashInfoContent = document.getElementById('hashInfoContent');
        var alarmTimeout;
        var checkInterval = null; // No initial interval
        var changesDetected = <?php echo $changesDetected ? 'true' : 'false'; ?>;

        function checkForChanges(playAudio = false) {
            var formData = new FormData(checkForm);
            fetch('index.php', {
                method: 'POST',
                body: formData
            })
            .then(response => response.text())
            .then(html => {
                var parser = new DOMParser();
                var doc = parser.parseFromString(html, 'text/html');
                
                var newStatus = doc.querySelector('.status').textContent;
                var newLastCheck = doc.querySelector('.last-check').textContent;
                var newHashInfo = doc.querySelector('.hash-info');

                statusContainer.textContent = newStatus;
                statusContainer.className = doc.querySelector('.status').className;
                lastCheckContainer.textContent = newLastCheck;

                if (newHashInfo) {
                    hashInfoContainer.style.display = 'block';
                    hashInfoContent.innerHTML = newHashInfo.innerHTML;
                } else {
                    hashInfoContainer.style.display = 'none';
                }

                if (playAudio && newStatus.includes('Changes detected')) {
                    audio.currentTime = 0; // Reset audio to start
                    audio.play();
                    // Stop audio after 5 minutes
                    alarmTimeout = setTimeout(function() {
                        audio.pause();
                    }, 300000); // 5 minutes
                } else {
                    audio.pause(); // Stop audio if no changes
                }

                // If no changes detected, check again after 10 seconds
                if (!newStatus.includes('Changes detected')) {
                    clearTimeout(checkInterval);
                    checkInterval = setTimeout(function() {
                        checkForChanges(false);
                    }, 10000); // 10 seconds
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('An error occurred while checking for changes.');
            });
        }

        checkForm.addEventListener('submit', function(event) {
            event.preventDefault(); // Prevent default form submission
            checkForChanges(true); // Play audio if changes are detected
        });

        // Check for changes every 10 seconds if no changes detected
        if (!changesDetected) {
            checkInterval = setInterval(function() {
                checkForChanges(false);
            }, 10000); // 10 seconds
        }
    });
    </script>
</body>
</html>
)in this codes, when deteded don't stop alarm for 10mins make it loop for 10mins, then start again i hope you understand me and type full codes