Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2004-08-10, 04:06 AM   #1
raymor
The only guys who wear Hawaiian shirts are gay guys and big fat party animals
 
Join Date: Jan 2004
Posts: 178
Send a message via ICQ to raymor
PHP pack() troubles (I will PayPal for expert help)

'm looking for someone who is very familar with PHP
pack and unpack() magic for help with a script I'm working on.
I wrote a Perl script to query an ntp (time) server and I
need to port it to PHP. I've got most of it, but using the
named parameters with unpack() is foreign to me and
I've got some long, complicated unpacking to do. Looking
at the docs and at my code makes my head swim.

Here's my original (working) Perl script:
http://proxycheck.bettercgi.com:81/time.pl.txt
Mostly ported to PHP, with a bit of work left:
http://proxycheck.bettercgi.com:81/time.php.txt
__________________
Ray Morris
support@bettercgi.com
Strongbox/Throttlebox & more
TXDPS #A14012
raymor is offline   Reply With Quote
Old 2004-08-10, 04:08 AM   #2
raymor
The only guys who wear Hawaiian shirts are gay guys and big fat party animals
 
Join Date: Jan 2004
Posts: 178
Send a message via ICQ to raymor
Those URLs should have been:

http://proxycheck.bettercgi.com:81/time_pl.txt
and
http://proxycheck.bettercgi.com:81/time_php.txt
__________________
Ray Morris
support@bettercgi.com
Strongbox/Throttlebox & more
TXDPS #A14012
raymor is offline   Reply With Quote
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
Old 2004-08-18, 09:16 PM   #4
raymor
The only guys who wear Hawaiian shirts are gay guys and big fat party animals
 
Join Date: Jan 2004
Posts: 178
Send a message via ICQ to raymor
Thanks. I had actually seen that but wanted to use
NTP rather than time or daytime protocols.
Most time servers only support ntp now and allso the time
formats for time and daytime and not well defined.
__________________
Ray Morris
support@bettercgi.com
Strongbox/Throttlebox & more
TXDPS #A14012
raymor is offline   Reply With Quote
Reply


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 07:41 AM.


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