COUNTDOWN - GIVEN in MIN...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
poeta_eletrico
Forum Commoner
Posts: 32
Joined: Mon Dec 22, 2003 7:33 am
Contact:

COUNTDOWN - GIVEN in MIN...

Post by poeta_eletrico »

Hi,


I read a lot of posts as COUNTDOWN - 25 at all found on my search here. But no ones seems to completly cover a simple question:


1. If the PROGRAMMER needs to have that COUNT on every single page and it s not using an IFRAME or else.
2. When the user get LOGGED IN it´s code records the 'future min to come' into COOKIE and the parse this cookie like:

$expiredate=mktime(date('H'),date('i')+30,0,date('m'),date('d'),date('Y'));
setcookie("living", $expiredate, $expiredate);

$future=split(':',strftime('%T',$_COOKIE['living']));
$now=split(':',strftime('%T',time()));
Displayed METHOD IS: XX min YY sec (used in every page).

When the time has come 00 MIN 00 SEC - I´ll recall an action and UNSET all SESSIONS and COOKIES used and DO LOGOUT to that specific user. I round and round the internet and developed a code but I´m getting in trouble subtracting min by the seconds. I tried to MIX javascript with PHP but I did not find any suitable manner for that.

Can anyone here comment my problem with any TIP or CLUE?

Thanks in advance for all of you.

Bye,
Poeta_Eletrico
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I guess Javascript is the only way.
You can try implementing AJAX in this case.
But you cannot stop anyone from not counting down to 0 if the user disables JS for this reason.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the only thing you can do server-side is store information on a "best guess" of when to expect the response. (Basically, it's the time alotment you want to use plus some extra time for transmission delays and such.) If the time passes, you kill their session and redirect them or display the logged out page instead of continuing.
poeta_eletrico
Forum Commoner
Posts: 32
Joined: Mon Dec 22, 2003 7:33 am
Contact:

Post by poeta_eletrico »

anjanesh wrote:I guess Javascript is the only way.
You can try implementing AJAX in this case.
But you cannot stop anyone from not counting down to 0 if the user disables JS for this reason.
Hi anjanesh,

Thanks for your response. But as not a programmer (experienced one) - I think AJAX is a little bit out of my scope at this moment. But that´s very interesting to study to and I´ll search for documents related.

Kind Regards,
Poeta_Eletrico
poeta_eletrico
Forum Commoner
Posts: 32
Joined: Mon Dec 22, 2003 7:33 am
Contact:

Post by poeta_eletrico »

feyd wrote:the only thing you can do server-side is store information on a "best guess" of when to expect the response. (Basically, it's the time alotment you want to use plus some extra time for transmission delays and such.) If the time passes, you kill their session and redirect them or display the logged out page instead of continuing.
Hi feyd,

"BEST GUESS" Sorry but i misunderstood this part :D can u describe it in my newbie language?

I have this portion of code running besides with the DISPLAY COUNTDOWN. That works properly behind the scenes cos is not responsible to SHOW ANYTHING, but just checking out :

Code: Select all

<? if($present < $future){
      echo $mins." min : ".$num4." sec";
}else{ 
      echo "<script type="text/javascript">
<!--
      window.location = "http://myserver.com/?do_logout=yes"
//-->
      </script>";
}?>
Is not necessary to me have a SERVER-SIDE countdown got it? Because as I store my FUTURE MIN TIME to countdown in a COOKIE so I can use CLIENT-SITE and when this time is UP recall the code above, got it?

Thanks for your attention anyway.

Poeta_Eletrico
Post Reply