This is not a very good idea to use PHP instead of JS for this type of task. Anyway we can implement countdown timer via PHP, but if we want to show it on the web page we also need to use AJAX request to update our data.
index.html:
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
</head>
<body>
<h1 id="countdown"></h1>
<script>
jQuery(document).ready(function() {
time=setInterval(function(){
jQuery(function () {
jQuery.ajax({
url: "countdown.php",
method: 'post',
dataType: 'json',
data: {},
complete: function (data) {
jQuery("#countdown").html(data.responseText);
}
});
});
},1000);
});
</script>
</body>
</html>
countdown.php:
<?php
echo date("i:s",3600-(date("s",time())))." left";
exit();
If you need only minutes left (without seconds), your code should look like this:
echo (60-(date("i",time()))." min left");
See also:
https://www.w3schools.com/howto/howto_js_countdown.asp
The simplest possible JavaScript countdown timer?