Answer the question
In order to leave comments, you need to log in
How to get the exact time in PHP?
Hello! The computer where the page is displayed has the wrong time, so it will not be possible to display it correctly using the js date(). Now I do this: since the time is correct on the server, I simply put it in a div, and then using js I break it into components and increase it every second.
I read that there are exact time servers that work with the NTP protocol. As far as I understand, it's the users' servers that should take their time. Is it possible to make a request directly from PHP to such an exact time server?
Googled this code
function query_time_server ($timeserver, $socket) {
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) */
$fp = fsockopen($timeserver,$socket,$err,$errstr,5);
# parameters: server, socket, error code, error text, timeout
if ($fp) {
fputs($fp,"\n");
$timevalue = fread($fp,49);
fclose($fp); # close the connection
}
else {
$timevalue = " ";
}
But it doesn't work. Tried to use different ports and quite a few different servers, but nothing works. Does anyone know if it is possible to get the exact time from the NTP server from PHP at all?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question