JS
var audio = new Audio('Girtab.mp3'); // ses dosyasının URL'si burada belirtilir
// setTimeout(function() {
// audio.play(); // sayfa yüklendiğinde ses dosyası otomatik olarak oynatılır
// }, 1000);
setInterval(function() {
// Veritabanını kontrol etmek için Ajax isteği gönder
var xhr = new XMLHttpRequest();
xhr.open('POST', 'veritabani_kontrol.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// Veritabanında yeni veri varsa, sayfayı yenile
if (xhr.responseText === '1') {
audio.play();
setTimeout(function() {
location.reload();
}, 2000);
}
}
};
xhr.send();
}, 5000); // 5 saniyede bir kontrol yapPHP<?php
try{
include("connect.php");
// Veritabanındaki son siparişin zaman bilgisini al
$stmt = $baglan->prepare("SELECT zaman FROM siparisonay ORDER BY id DESC LIMIT 1");
$stmt->execute();
$zaman = $stmt->fetchColumn();
// Eğer son sipariş 5 dakikadan önce yapılmışsa yeni veri yoktur
if (time() - strtotime($zaman) > 300) {
echo 0;
} else {
echo 1;
}
} catch(PDOException $e) {
echo "Hata: " . $e->getMessage();
}
?>
