Jump to content

Count down timer to actually count down


Equium

Recommended Posts

Hi basically i run a only text  based mafia game

 

After you commit a GTA it says you need to wait 2 mins but loads the time you have to wait like this:

 

You need to lay low for a little while.
00:03:56

 

and stays like that i would like it to actually count down while your on the page not have to keep refreshing.

 

How would i go about doing this here is the code for that snippet:

 

<?php

if($rank >= "2"){
if(time() <= $gta_information[0]){
if(!$_POST['Commit']){            
echo "You need to lay low for a little while.<br />".date( "00:i:s", $gta_information[0] - time() );
    }
 

Link to comment
Share on other sites

This cant be done with PHP alone.

 

The countdown will have be handled by javascipt. You'd only use PHP to initiate the timer

 

 

 

 

hmm why is my topic not showing up

What do you mean? It is listed in the PHP Coding Help forum

Edited by Ch0cu3r
Link to comment
Share on other sites

<head>
<meta http-equiv="REFRESH" content="5;url=http://www.google.com" target="_self">
</head><body oncontextmenu="return false;">


<p>You'll be automatically redirected in <span id="count">5</span> seconds...</p>


<script type="text/javascript">


window.onload = function(){


(function(){
  var counter = 5;


  setInterval(function() {
    counter--;
    if (counter >= 0) {
      span = document.getElementById("count");
      span.innerHTML = counter;
    }


    if (counter === 0) {
        alert('BYE');
        clearInterval(counter);
    }


  }, 1000);


})();


}


</script>

Try this, works like a charm for me :)

 

I use it as a re-directory. When the timer has finished its 5 seconds, it will re-direct to google.com

You can change it to suit your needs though.It's fairly simple

 

Edited by alphamoment
Link to comment
Share on other sites

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.