Jump to content


Photo

Live Countdown (Not date or time


  • Please log in to reply
1 reply to this topic

#1 lukeprice

lukeprice
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 July 2006 - 11:10 AM

Hi,

I am currently attempting to develop an online game. I have so far achieved the results I want using JavaScript but have now been informed it would be easy to cheat because JavaScript is client side.

So I have now began attempting to achieve the same results using PHP. Ive started trying to rescript the countdown timer but can't seem to get a satisfactory alternative to setTimeout (in JS). I have tried sleep() and usleep() but i'm either using them incorrectly or they won't do what I need.

The link to what the 'game' (in inverted commas because its far from that yet) should be like (in JS) is here: http://www.bibliocom...t/chop_wood.php

The code for the alternative countdown timer I have been working on is here but it will not work, it keeps reposting the same values. Like I said I tried using sleep(), but then the page doesn't even load! Here is the code:


PHP Code:
<?php

function display(){

$milisec = 0;
$seconds = 5;

$milisec -= 1;

	if ($milisec <= -1){
	    $milisec = 9;
	    $seconds -= 1;
	    }
		
	do
	{
	echo $seconds.".".$milisec;
	}
	while ($milisec > 0 && $seconds > 0);
	       	
}

display();

?> 

And a link to a working version here: http://www.bibliocom...hp_function.php WARNING: Don't visit the link if you don't want your browser to crash! It might not, but then again...


I just need some way to pause the script for a second then execute it again, then pause, then execute and so on...

Thank you in advance.


#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 14 July 2006 - 11:38 AM

PHP would only be useful for example a crossword where they only had a certain time to complete it. By inserting the time into the page when they start you can check the time taken at the end, avoiding cheating.
However, PHP cannot be used in the context of live client-side interaction, except for making calls to PHP from Javascript to check the time, which could be foiled too.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users