show an error message or block if the time and date of the computer is not correct php

0

I need to do with php a time check, one that shows me an error message if the time of the computer is less than the server that shows an alert message, so far with much help I got bring the 2 dates but, the values of the 2 as such are not remotely close

hagp the test and the time converted to an integer in javascript throws me

1533156284660

and the php time throws me

998122565

index.php

   <script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>

<script type="text/javascript">
var f=new Date();
var hora=f.getTime(); 
$.post("hora.php",{hora:hora},function(d){alert(d)});
</script>

hora.php

<?php
//configuro la zona horario de mi server 
date_default_timezone_set('America/Manaus');
//tomo la hora del servidor
$hora = strtotime(date('d-m-y h:i:s'));
// esto es un if corto y comparo el post que mande de index con la hora del servidor
$hora == $_POST['hora'] ? $res = "Es igual" : $res = "No es igual";
echo $_POST["hora"]." - ".$hora;
?>
    
asked by Juan Ortiz 31.07.2018 в 22:58
source

1 answer

2

you can try the following

index.html

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="utf-8">
</head>
<body>
<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"
  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
  <script>
    //obtiene fecha del ordenador local
    var f=new Date();
    //obtiene solo la hora y minutos poniendo los ceros a la izquierda
    var hora=('0' + f.getHours()).slice(-2)+":"+('0'+f.getMinutes()).slice(-2); 
    //manda el post a la pagina hora.php con la informacion de la hora
    $.post("hora.php",{hora:hora},function(d){alert(d)});
  </script>
</body>
</html>

hora.php

<?php
//configuro la zona horario en mi caso es chihuahua
date_default_timezone_set('America/Chihuahua');
//tomo la hora del servidor
$hora = date('H:i');
// esto es un if corto y comparo el post que mande de index con la hora del servidor
$hora == $_POST['hora'] ? $res = "Es igual" : $res = "No es igual";
echo $res;
    
answered by 31.07.2018 в 23:47