Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 2004-08-18, 08:58 PM   #3
Pazz
WHO IS FONZY!?! Don't they teach you anything at school?
 
Join Date: Apr 2003
Location: Australia
Posts: 42
Send a message via ICQ to Pazz
Why do you need to pack and unpack?

If you just want to query a time server this does it using port13 and port37.

Thanks to google, Ralf at qrq.de and some modifications by me.

<?php
function query_time_server ($timeserver, $socket) {
$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);
}
else {
$timevalue = " ";
}
$ret = array();
$ret[] = $timevalue;
$ret[] = $err;
$ret[] = $errstr;
return($ret);
}

$timestamp = time();
$datum = date("Y-m-d (D) H:i:s",$timestamp);
echo "Current date and local time on this server is $datum <br>\n";

$timeserver = "time-C.timefreq.bldrdoc.gov";
$timercvd = query_time_server($timeserver,37);
if (!$timercvd[1]) { # if no error from query_time_server
$timevalue = bin2hex ($timercvd[0]);
$timevalue = abs (HexDec('7fffffff') - HexDec($timevalue) - HexDec('7fffffff')) ;
$tmestamp = $timevalue - 2208988800; # convert to UNIX epoch time stamp
$datum = date("Y-m-d (D) H:i:s",$tmestamp - date("Z",$tmestamp)); /* incl time zone offset */
$doy = (date("z",$tmestamp)+1);

echo "Time check from time server <font color=\"red\">",$timeserver,"</font>.<br>\n"
."The current date and universal time is <font color=\"red\">",$datum,"</font> UTC.<br>\n"
."<font color=\"red\">",$timevalue,"</font> seconds since 1900-01-01 00:00.00.<br>\n"
."It is day <font color=\"red\">",$doy,"</font> of this year.<br>\n"
."The unix epoch time stamp is <font color=\"red\">$tmestamp.</font><br>\n";
}
else {
echo "Unfortunately, the time server $timeserver could not be reached at this time. "
."$timercvd[1] $timercvd[2].<br>\n";
}

$timercvd = query_time_server($timeserver,13);
if (!$timercvd[1]) {
$timevalue = $timercvd[0];
echo "Or if you prefer [<font color=\"red\">",$timevalue,"</font>].<br>\n";
}
else {
echo "Unfortunately, the time server $timeserver could not be reached at this time. "
."$timercvd[1] $timercvd[2].<br>\n";
}
?>
__________________
Artificial intelligence is no match for natural stupidity
Pazz is offline   Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:27 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc