Tuesday, March 2, 2010

Diplaying Server Date Using PERL and Javascript

I only find PHP solution after googling around, but I wanted to use PERL. Here’s how I did it:


PERL side:

#!/usr/bin/perl

$time = localtime(time);
print "Content-type: text/html\n\n";
print "var serverdate='$time';";
exit;


Javascript side:

<script language="JavaScript" src="/cgi-bin/getservertime"></script>
<script type="text/javascript">
<!--
document.getElementById('time').innerHTML = '<font face=tahoma size=1>'+serverdate+'</font>';
//-->
</script>




Please place a <div id=”time”> </div> somewhere in the your HTML body to receive the server date from this javascript. The PERL script name is getservertime and you can change accordingly if you like.

No comments:

Post a Comment