...

View Full Version : how would you solve this? count



Trki
04-20-2012, 02:09 PM
Hi all coders :P

I am going to do ( for me ) something like countdown ... to example 50s countdown... and when countdown will be 0 then do some php code... i think this will be no a problem because its just a JS and some connect to php. but... i have problem when a user have 50s ... then counter is counting down the numbers... 45 ... and counting and counting... 20 and when he is on number 20 (to example ) he decides close browser... but i want to do some php code after 50s even if he close the browser...

I hope i explained my problem well and u will help me figure out, how can i do it... THX A LOT!! :P

Fou-Lu
04-20-2012, 03:58 PM
You can't. If you're using JS to invoke the script, once the user is gone that countdown is terminated since JS is client side.
PHP can only countdown based on sleep, and will only make the page appear as loading. PHP can be set to ignore_user_abort() if they leave the page.
Saying this, you can mix the two and invoke a JS right from the beginning that calls a PHP page that sleeps for 50 seconds and ignores user abort, then executes a given code block. You can also do this using just PHP, but it takes a little more work since you can't call the sleeping script in a conventional inclusion manner, you'll need to connect to it via an HTTP method such as curl so you can abandon it in the calling script. Otherwise your just wasting time with two scripts since it will hang up the calling script until its done anyway.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum