it sitll smae thing (<?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−dH:i:s′);fileputcontents(logFile, "[timestamp]message\n", FILE_APPEND);
}
// Function to get the last check time from the log
function getLastCheckTime() {
logFile=′changelogFile)) {
logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (!empty(lastLine = end(lastLine, 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://lolastCheckTime = getLastCheckTime();
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());
}
}
?>
<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 changesDetected = <?php echo json_encode($changesDetected); ?>;
var audioPlaying = false;
var checkInterval = null;
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 (newStatus.includes('Changes detected') && playAudio && !audioPlaying) {
audio.currentTime = 0; // Reset audio
audio.play();
audioPlaying = true;
// Stop alarm after 10 minutes
setTimeout(() => {
audio.pause();
audioPlaying = false;
}, 600000); // 10 minutes
// Stop checking for changes while alarm is playing
clearInterval(checkInterval);
} else if (!newStatus.includes('Changes detected')) {
// Check again in 10 seconds if no change detected
clearInterval(checkInterval);
checkInterval = setInterval(() => {
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
});
// Start checking for changes every 10 seconds if no changes detected
if (!changesDetected) {
checkInterval = setInterval(() => {
checkForChanges(false);
}, 10000); // 10 seconds
}
});
</script>