Jump to content

Recommended Posts

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: [url=http://www.bibliocommerce.com/test/chop_wood.php]http://www.bibliocommerce.com/test/chop_wood.php[/url]

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:


[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();

?>
[/code]

And a link to a working version here: [url=http://www.bibliocommerce.com/test/php_function.php]http://www.bibliocommerce.com/test/php_function.php[/url] 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.
Link to comment
https://forums.phpfreaks.com/topic/14576-live-countdown-not-date-or-time/
Share on other sites

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.