Get Date And Time From A Time Server (Class File)

<?php
interface aRzIntefaceTimeServerTime
{
public function aRzFunGetTimeServerTime( $argTimeServerName = “time-C.timefreq.bldrdoc.gov”, $argTimeSergerSoket = 13 );
}
?>
<?php
class aRzClsTimeServer
{
private $aRzVarFilePointer = NULL;
private $aRzRetVal = array();
private $aRzVarTimeValue = NULL;
private $aRzVarErrNo = NULL;
private $aRzVarErrStr = NULL;

function __construct()
{
unset( $this->aRzRetVal );
if( $aRzVarFilePointer )
{
@fclose( $aRzVarFilePointer );
}
}
protected function aRzFunConnectAndQuery( $argTimeServerName, $argTimeSergerSoket )
{
$this->aRzVarFilePointer = @fsockopen( $argTimeServerName, $argTimeSergerSoket, $this->aRzVarErrNo, $this->aRzVarErrStr, 5 );
if ( $this->aRzVarFilePointer )
{
@fputs( $this->aRzVarFilePointer, “\n” );
$this->aRzVarTimeValue = @fread( $this->aRzVarFilePointer, 49 );
@fclose( $this->aRzVarFilePointer );
}
else
{
$this->aRzVarTimeValue = ” “;
}
unset( $this->aRzRetVal );
$this->aRzRetVal[] = $this->aRzVarTimeValue;
# error code
$this->aRzRetVal[] = $this->aRzVarErrNo;
# error text
$this->aRzRetVal[] = $this->aRzVarErrStr;
return( $this->aRzRetVal );
}
function __destruct()
{
unset( $this->aRzRetVal );
if( $aRzVarFilePointer )
{
@fclose( $aRzVarFilePointer );
}
}
}
?>
<?php
class aRzClsTimeServerTime extends aRzClsTimeServer implements aRzIntefaceTimeServerTime
{
private $aRzRetVal = array();
private $aRzVarTheTime = array();
function __construct()
{
unset( $this->aRzRetVal );
unset( $this->aRzVarTheTime );
}
public function aRzFunGetTimeServerTime( $argTimeServerName = “time-C.timefreq.bldrdoc.gov”, $argTimeSergerSoket = 13 )
{
unset( $this->aRzRetVal );
unset( $this->aRzVarTheTime );
$this->aRzVarTheTime = parent::aRzFunConnectAndQuery( $argTimeServerName, $argTimeSergerSoket );
if( !$this->aRzVarTheTime[ 1 ] )
{
$aRzVarTimeValue = bin2hex ( $this->aRzVarTheTime[ 0 ] );
$aRzVarTimeValue = abs ( HexDec( ‘7fffffff’ ) – HexDec( $aRzVarTimeValue ) – HexDec( ‘7fffffff’ ) ) ;
# convert to UNIX epoch time stamp
$aRzVarTimeStamp = $aRzVarTimeValue – 2208988800;
#Array Index = 0
$this->aRzRetVal[] = $aRzVarTimeValue – 2208988800;
/* incl time zone offset */
#Array Index = 1
$this->aRzRetVal[] = strtotime( date( “Y-m-d H:i:s”, $aRzVarTimeStamp – date( “Z”, $aRzVarTimeStamp ) ) );
$this->aRzRetVal[] = date( “Y-m-d H:i:s”, $aRzVarTimeStamp – date( “Z”, $aRzVarTimeStamp ) );
//echo date( “Y-m-d ( D ) H:i:s”, $aRzVarTimeStamp – date( “Z”, $aRzVarTimeStamp ) );
$this->aRzRetVal[] = ( date( “z”, $aRzVarTimeStamp ) + 1 );
}
else
{
#Array Index = 0
$this->aRzRetVal[] = ” “;
#Array Index = 1
$this->aRzRetVal[] = ” “;
#Array Index = 2
$this->aRzRetVal[] = ” “;
#Array Index = 3
$this->aRzRetVal[] = ” “;
#Array Index = 4
$this->aRzRetVal[] = $this->aRzVarTheTime[ 1 ];
$this->aRzRetVal[] = $this->aRzVarTheTime[ 2 ];
}
return $this->aRzRetVal;
}
function __destruct()
{
unset( $this->aRzRetVal );
unset( $this->aRzVarTheTime );
}
}
?>
<?php
$aRzVarTimeArray = array();
$aRzObjTimeServerTime = new aRzClsTimeServerTime();
$aRzVarTimeArray = $aRzObjTimeServerTime->aRzFunGetTimeServerTime( “time-C.timefreq.bldrdoc.gov”, 37 );
if( !$aRzVarTimeArray[ 4 ] )
{
echo date( “Y-m-d H:i:s”, $aRzVarTimeArray[ 1 ] );
echo “<br />”;
}
echo “<br />”;
echo “<br />”;
echo “<br />”;
?>
<?php # PHP V4
function query_time_server( $timeserver, $socket )
{
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$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 = ” “;
}
$ret = array();
$ret[] = $timevalue;
$ret[] = $err;     # error code
$ret[] = $errstr;  # error text
return( $ret );
} # function query_time_server
?>
<?php
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$timeserver = “time-C.timefreq.bldrdoc.gov”;
$timercvd = query_time_server($timeserver,13);
if ( !$timercvd[ 1 ] )
{
# if no error from query_time_server
$timevalue = $timercvd[ 0 ];
echo “Time check from time server “, $timeserver, ” : [<font color=\”red\”>”, $timevalue, “</font>].<br>\n”;
echo “<br />”;
echo date( “Y-m-d”, $timevalue );
echo “<br />”;
} #if (!$timercvd)
else
{
echo “Unfortunately, the time server $timeserver could not be reached at this time. “;
echo “$timercvd[1] $timercvd[2].<br>\n”;
} # else
?>
<?php
/* Query a time server
(C) 1999-09-29, Ralf D. Kloth (QRQ.software) <ralf at qrq.de> */
$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 “, $timeserver, ” : [<font color=\”red\”>”, $timevalue, “</font>]”;
echo ” (seconds since 1900-01-01 00:00.00).<br>\n”;
echo “The current date and universal time is “, $datum, ” UTC. “;
echo “It is day “, $doy, ” of this year.<br>\n”;
echo “The unix epoch time stamp is $tmestamp.<br>\n”;
} #if (!$timercvd)
else
{
echo “Unfortunately, the time server $timeserver could not be reached at this time. “;
echo $timercvd[ 1 ] . ” ” . $timercvd[ 2 ] . “<br>\n”;
} # else
?>
<a href=”http://www.kloth.net/software/timesrv1.php&#8221; target=”_blank”>Linked»»</a>

Advertisements
By Rz Rasel Posted in Php

3 comments on “Get Date And Time From A Time Server (Class File)

  1. Hello admin. I discovered your “https://arzrasel.wordpress.com/2012/07/23/get-date-and-time-from-a-time-server-class-file/” page via Google but it was hard to find as you were not on the first page of search results. This means you are missing out on a ton of website traffic from the search engines. I have found a website which offers to dramatically increase your rankings and traffic to your site: http://venueseo.com/7-day-free-trial. I managed to get close to 1000 visitors per day using their services, you could also get lot more targeted traffic from search engines than you have now. Hope this helps 🙂 Take care.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s