Updating server time.

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Updating server time.

Post by Torniquet »

If you want a little clock that tells you the time of the server (which is kinda what i was looking for a while ago but for flash)

never the less this does the jobby.

it uses an iframe as its display, with a seperate script which gets the time and refreshes the time every x seconds.

firstly. add the following to your header or where ever you want it displayed.

Code: Select all

<iframe src="../scripts/time.php" width="130" height="40" border="0" frameborder="0" marginwidth="1" marginheight="0" align="middle"></iframe>
then you need to make a 'time.php' file and add it to what ever folder (in my case its the scripts folder)

then input the following into this new file.

Code: Select all

<head>
<meta http-equiv="refresh" content="10;url=time.php" />
</head>

<body>
<?php

$time = date("H:i");
$date = date("d/m/y");
echo "<div align='center'>";
echo $date;
echo "<br />";
echo $time;
echo "</div>";
?>
</body>
as you can probably see, through <meta http-equiv="refresh" content="10;url=time.php" />, it is ordering a refresh every 10 seconds to the url 'time.php'

i dont completly understand all this, but it was made from a different tutorial for a flat based shoutbox, which i adapted. http://www.trap17.com/index.php/flat-ba ... 57148.html

its 100% working though. so thats all i care about. thought i would share :)
New Site Coming Soon! Stay tuned :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Updating server time.

Post by hallsofvallhalla »

thanks for sharing this!
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: Updating server time.

Post by Falken »

A ok script.

Altho there are some issues with it, having a page constantly update the time each 10 seconds for lets say 1000 players is a lot of php script calls.

A better way would be to just get the time from PHP once, and then let a javascript keep a clock running, also making it look better.

Just some suggestions, could be a good way to start learning javascript :)
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
Post Reply

Return to “Coding”