PHP countdown timer example
Here we present you very easy and effective way to create countdown timer on php. All you need is to follow these instructions and in a few minutes you will get an own timer. Such type of countdown timer doesn't have the best visual attraction, but in the same time it functions without a hitch. It will definitely save your time, if you use this method on your webpage.There are some cases to use such php countdown timer. The most common one is to illustrate how much time left before user may get access to peculiar possibility. Also you may show any short-term process on the website and it will make page looks better. So you need to do following steps:
How to make a countdown using PHP
First of all you need to disallow server keep cash and allow durable execution of script with the next lines of PHP code
<?
@ini_set('zlib.output_compression', 'Off');
header('X-Accel-Buffering: no');
@ini_set('implicit_flush',1);
@ob_end_clean();
set_time_limit(0);
?>
Note that this part of code should be written in first line of your page, because it contains headers. You'll have an error "
Warning: Cannot modify header information - headers already sent by blablabla...
" otherwise.
PHP Timer Countdown
Than you may write anything you need to show guests of your page before timer (instantly):
<?
echo 'Something will appear below after ';
?>
Create a Countdown Timer for Websites With PHP
And the next will be our Countdown Timer code:
<?
ob_implicit_flush(1);
for ($i=20; $i>0; $i--) {
echo $i," ";
sleep(1);
}
?>
Build a Countdown Timer in just 10 lines of PHP
Last thing you could add - some content, that you desire to show with the delay of our Countdown Timer:
<? echo 'Delayed text'; ?>
Learn How to Create a PHP Countdown Timer
The whole code looks like below:
<?
@ini_set('zlib.output_compression', 'Off');
header('X-Accel-Buffering: no');
@ini_set('implicit_flush',1);
@ob_end_clean();
set_time_limit(0);
echo 'Something will appear below after ';
ob_implicit_flush(1);
for ($i=20; $i>0; $i--) {
echo $i,' ';
sleep(1);
}
echo 'Delayed text';
?>
But this PHP Countdown Timer doesn't refresh shown digits =( If you have any suggestions on how to do this - don't hesitate to write me through Contact form.