Jump to content

Countdown Activation, sorta


Lukela

Recommended Posts

Sounds like you're looking at Javascript.

 

PHP is server-side only. Javascript is what you'll need, as its client-side.

 

PHP can do this as well, with the sleep function:

 

example from php.net:

<?php

// current time
echo date('h:i:s') . "\n";

// sleep for 10 seconds
sleep(10);

// wake up !
echo date('h:i:s') . "\n";

?>

 

you could use this for pretty much anything:

<?php

echo "Bob: this is fun";

sleep(10);

echo "Tom: yes it is";

?>

 

Regards ACE

 

 

Link to comment
Share on other sites

Sounds like you're looking at Javascript.

 

PHP is server-side only. Javascript is what you'll need, as its client-side.

 

PHP can do this as well, with the sleep function:

 

example from php.net:

<?php

// current time
echo date('h:i:s') . "\n";

// sleep for 10 seconds
sleep(10);

// wake up !
echo date('h:i:s') . "\n";

?>

 

you could use this for pretty much anything:

<?php

echo "Bob: this is fun";

sleep(10);

echo "Tom: yes it is";

?>

 

Regards ACE

 

 

Try 'overwriting the same data' however, as a countdown is normally done.

 

Edit: Re-read first post.

Question: Did you want it to display a countdown or what-not?

Link to comment
Share on other sites

The thing is that, what if they leave the page? Wont it restart if they go back? Plus what I am trying to do is to input the time into the database and make it so they can go browse the site and the timer goes down still.

It might help if you explicitly tell us what you're trying to do.

It can usually fill in a few blanks, and make things easier to solve. :)

Link to comment
Share on other sites

I have this Browser-based game I am building with PHP and very basic Javascripts(cause I do not know). So when someone attacks, there is a time difference on how long it takes till there troops reach there target. That will be the timer, so when the timer hits 0 it will comense the attack script.

Link to comment
Share on other sites

I have this Browser-based game I am building with PHP and very basic Javascripts(cause I do not know). So when someone attacks, there is a time difference on how long it takes till there troops reach there target. That will be the timer, so when the timer hits 0 it will comense the attack script.

In that case, the PHP sleep function might be best.

eg:

<?
echo "Walking to destination...<br />"; 
sleep(3);
echo "Walking...<br />";
sleep(5);
echo "Reached destination";
-- rest --
?>

Link to comment
Share on other sites

 

 

no, but I know what you mean now. I make Text Browser games myself. *looks at signature*

 

I'm guessing you have a "attack" table in your database or something like that, which has "attacking user id", "defending user id" and the rest of it... what you need is another column in the attack table and name it something like "ETA"(estimated time of arrival) and.... I'm running low on ideas now... could do a cronjob to run every 5 mins or something to update the ETA column. but this will take away the accuracy of the ETA. Really depends on how long the estimated time of arrival, or attack is, like would you measure the time in hours, mins, secs or days??

 

EDIT: sorry just saw what you posted above...

Is someone able to browse other pages while this is happening? Cause the attack can take hours, days, or minutes

 

Regards ACE

Link to comment
Share on other sites

Yeah If there was a way in PHP I think I woulda found out already :( I guess it is in JS my answer, it has to be very accurate. >.<

 

-goes to google books to search for a Javascript for dummies book-

 

Guess I got alot of learning to do! lolx

Link to comment
Share on other sites

 

 

no, but I know what you mean now. I make Text Browser games myself. *looks at signature*

 

I'm guessing you have a "attack" table in your database or something like that, which has "attacking user id", "defending user id" and the rest of it... what you need is another column in the attack table and name it something like "ETA"(estimated time of arrival) and.... I'm running low on ideas now... could do a cronjob to run every 5 mins or something to update the ETA column. but this will take away the accuracy of the ETA. Really depends on how long the estimated time of arrival, or attack is, like would you measure the time in hours, mins, secs or days??

 

EDIT: sorry just saw what you posted above...

Is someone able to browse other pages while this is happening? Cause the attack can take hours, days, or minutes

 

Regards ACE

Set a session variable for the expiration time, and one to say you're attacking. On page load of the attack script, check the session variable to see if its <= the current time AND that the one that says you're attacking is set. If both of those things are true, UNSET those variables and proceed with your attack script.

Simple. :)

As for displaying how long, basically:

$time_to_go = $_SESSION['expire_time'] - time();

Link to comment
Share on other sites

How am I suppose to run the script when the timer reaches to 0? PHP cant do that, I also want people be able to browse the website. So the SESSION cant reload on its on, so thats why I need JS. Although I dont know any JS, -picks up book- anyone wanna save me the time? Im going to start learning JS though but I need the code asap

 

 

 

no, but I know what you mean now. I make Text Browser games myself. *looks at signature*

 

I'm guessing you have a "attack" table in your database or something like that, which has "attacking user id", "defending user id" and the rest of it... what you need is another column in the attack table and name it something like "ETA"(estimated time of arrival) and.... I'm running low on ideas now... could do a cronjob to run every 5 mins or something to update the ETA column. but this will take away the accuracy of the ETA. Really depends on how long the estimated time of arrival, or attack is, like would you measure the time in hours, mins, secs or days??

 

EDIT: sorry just saw what you posted above...

Is someone able to browse other pages while this is happening? Cause the attack can take hours, days, or minutes

 

Regards ACE

Set a session variable for the expiration time, and one to say you're attacking. On page load of the attack script, check the session variable to see if its <= the current time AND that the one that says you're attacking is set. If both of those things are true, UNSET those variables and proceed with your attack script.

Simple. :)

As for displaying how long, basically:

$time_to_go = $_SESSION['expire_time'] - time();

Link to comment
Share on other sites

How am I suppose to run the script when the timer reaches to 0? PHP cant do that, I also want people be able to browse the website. So the SESSION cant reload on its on, so thats why I need JS. Although I dont know any JS, -picks up book- anyone wanna save me the time? Im going to start learning JS though but I need the code asap

 

 

 

no, but I know what you mean now. I make Text Browser games myself. *looks at signature*

 

I'm guessing you have a "attack" table in your database or something like that, which has "attacking user id", "defending user id" and the rest of it... what you need is another column in the attack table and name it something like "ETA"(estimated time of arrival) and.... I'm running low on ideas now... could do a cronjob to run every 5 mins or something to update the ETA column. but this will take away the accuracy of the ETA. Really depends on how long the estimated time of arrival, or attack is, like would you measure the time in hours, mins, secs or days??

 

EDIT: sorry just saw what you posted above...

Is someone able to browse other pages while this is happening? Cause the attack can take hours, days, or minutes

 

Regards ACE

Set a session variable for the expiration time, and one to say you're attacking. On page load of the attack script, check the session variable to see if its <= the current time AND that the one that says you're attacking is set. If both of those things are true, UNSET those variables and proceed with your attack script.

Simple. :)

As for displaying how long, basically:

$time_to_go = $_SESSION['expire_time'] - time();

Well if you have a header script that's included to every page (or executed before every page in any case), you can run the check then - if the page isn't the attack script, and the time is up -- header("Location: ./attack.php");

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.