Jump to content

Javascript/PHP problem


Thomisback

Recommended Posts

Hi everyone,

 

I have made a game in which you can build buildings, you have to wait for the time to elapse before you can build a new one. Currently I am using a Javascript script but this can easily be bypassed by changing your computers time! Now I am trying to convert it into PHP to make it more secure but I have got no clue where to start.

 

My javascript code looks like this:

<script   type="text/javascript">

v=new Date();
var bxx=document.getElementById('bxx');
function t(){
n=new Date();
ss={time};
s=ss-Math.round((n.getTime()-v.getTime())/1000.);
m=0;h=0;
if(s<0){
	bxx.innerHTML='{ready}<br><a href=link>{continue}</a>';
}else{
	if(s>59){m=Math.floor(s/60);s=s-m*60;}
	if(m>59){h=Math.floor(m/60);m=m-h*60;}
	if(s<10){s="0"+s}
	if(m<10){m="0"+m}
	bxx.innerHTML=h+':'+m+':'+s+'<br><a href="link">{cancel}<br><br>{name}</a>';
}
window.setTimeout("t();",999);
}
window.onload=t;

</script>

 

I'm sorry if my question is not appropriate for this forum, but thanks!

Link to comment
https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/
Share on other sites

you could have php write out the current time according to the server and store it in a hidden [display: none;] and DISABLED <input> where the value of this input is the servers time.  From there have javascript pickup that value to do its "has enough time passed?" calculations.

 

<?php
  echo '<input style="display: none;" value="' . date("H:i:s") . '" DISABLED />';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.