Salut din nou!
Am creat un site si m-am folosit de Smarty.
Cum as putea adauga un time ticker pe site, dar care sa-mi afiseze ora serverului, nu ora si data luata din browser?
Server time
Moderatori: coditza, Emil, Moderatori
-
florin_sb
- PHPRomania Supporter
- Mesaje: 22
- Membru din: Joi Aug 31, 2006 11:16 pm
- Localitate: Sibiu
- Contact:
Iata codul:
Am facut cu input-hidden pentru ca alta idee nu am avut cum sa trimit o variabila din php in javascript.
in fisierul php:
$time = time();
$tpl->assign("time",$time);
in template:
{literal}
<script language="JavaScript">
var clockID = 0;
Players = 0;
function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
var time;
time = document.getElementById("server_time");
tDate = new Date();
tDate = setTime(time);
var year, month, day, hour, minute, second;
year = tDate.getFullYear();
month = tDate.getMonth() + 1;
if (month < 10)
{month = "0" + month};
day = tDate.getDate();
if (day < 10)
{day = "0" + day};
hour = tDate.getHours();
if (hour < 10)
{hour = "0" + hour};
minute = tDate.getMinutes();
if (minute < 10)
{minute = "0" + minute};
second = tDate.getSeconds();
if (second < 10)
{second = "0" + second};
document.theClock.theTime.value = ""
+ year + "-"
+ month + "-"
+ day + " "
+ hour + ":"
+ minute + ":"
+ second;
clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
clockID = setTimeout("UpdateClock()", 500);
}
function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}
</script>
{/literal}
(...)
<form name="theClock">
<input type=hidden name="server_time" id="server_time" value="{$time}">
<input type=text name="theTime" size=22 class=time>
</form>
Rezultatu? Nimic. Adica inputul este gol.
Intai vreau sa vad ca imi arata ora serverului corect, apoi trec si la numaratul secundelor.
[/b]
Am facut cu input-hidden pentru ca alta idee nu am avut cum sa trimit o variabila din php in javascript.
in fisierul php:
$time = time();
$tpl->assign("time",$time);
in template:
{literal}
<script language="JavaScript">
var clockID = 0;
Players = 0;
function UpdateClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
var time;
time = document.getElementById("server_time");
tDate = new Date();
tDate = setTime(time);
var year, month, day, hour, minute, second;
year = tDate.getFullYear();
month = tDate.getMonth() + 1;
if (month < 10)
{month = "0" + month};
day = tDate.getDate();
if (day < 10)
{day = "0" + day};
hour = tDate.getHours();
if (hour < 10)
{hour = "0" + hour};
minute = tDate.getMinutes();
if (minute < 10)
{minute = "0" + minute};
second = tDate.getSeconds();
if (second < 10)
{second = "0" + second};
document.theClock.theTime.value = ""
+ year + "-"
+ month + "-"
+ day + " "
+ hour + ":"
+ minute + ":"
+ second;
clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
clockID = setTimeout("UpdateClock()", 500);
}
function KillClock() {
if(clockID) {
clearTimeout(clockID);
clockID = 0;
}
}
</script>
{/literal}
(...)
<form name="theClock">
<input type=hidden name="server_time" id="server_time" value="{$time}">
<input type=text name="theTime" size=22 class=time>
</form>
Rezultatu? Nimic. Adica inputul este gol.
Intai vreau sa vad ca imi arata ora serverului corect, apoi trec si la numaratul secundelor.
Cine este conectat
Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 7 vizitatori