Thomisback Posted June 17, 2008 Share Posted June 17, 2008 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 More sharing options...
grlayouts Posted June 17, 2008 Share Posted June 17, 2008 that the full code? ??? Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567650 Share on other sites More sharing options...
Thomisback Posted June 17, 2008 Author Share Posted June 17, 2008 I've got some other functions which need to be converted as well :/ this is one of them... Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567651 Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 And what exactly do want us to do? Were not here to write code for you. Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567653 Share on other sites More sharing options...
Thomisback Posted June 17, 2008 Author Share Posted June 17, 2008 I'm just wondering if there is an easy way to do this in PHP or whether someone knows a workaround to execute javascript on the server-side. Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567656 Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 What you could do is (when a user finishes creating a building) store the time the user finished in a database along with something that identifies the user. Then, if they try to create another building, check this database to see whether or not sufficient time has passed. Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567659 Share on other sites More sharing options...
xtopolis Posted June 17, 2008 Share Posted June 17, 2008 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 />'; ?> Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567664 Share on other sites More sharing options...
Thomisback Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks for your replies, i'm trying to figure it out Link to comment https://forums.phpfreaks.com/topic/110647-javascriptphp-problem/#findComment-567681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.