i'm working on countdown timer that's built php. i'm trying figure out how add message says "expired" after countdown timer reaches zero. can me adding feature countdown timer? i've listed code below.`
<?php date_default_timezone_set('australia/act'); include 'gifencoder.class.php'; $time = $_get['time']; $future_date = new datetime(date('r',strtotime($time))); $time_now = time(); $now = new datetime(date('r', $time_now)); $frames = array(); $delays = array(); $image = imagecreatefrompng('countdown.png'); $delay = 100; // milliseconds $font = array( 'size'=>73, 'angle'=>0, 'x-offset'=>10, 'y-offset'=>70, 'file'=>'transist.ttf', 'color'=>imagecolorallocate($image, 243, 139, 0), 'color2'=>imagecolorallocate($image, 217, 0, 0), ); for($i = 0; $i <= 60; $i++){ $interval = date_diff($future_date, $now); if($future_date < $now){ // open first source image , add text. $image = imagecreatefrompng('countdown.png');; $text = $interval->format('00:00:00:00'); imagettftext ($image , $font['size'] , $font['angle'] , $font['x-offset'] , $font['y-offset'] , $font['color'] , $font['file'], $text ); ob_start(); imagegif($image); $frames[]=ob_get_contents(); $delays[]=$delay; $loops = 1; ob_end_clean(); break; } else { // open first source image , add text. $image = imagecreatefrompng('countdown.png');; $text = $interval->format('%a:%h:%i:%s'); // %a weird in doesn’t give 2 digit number // check if starts single digit 0-9 // , prepend 0 if if(preg_match('/^[0-9]\:/', $text)){ $text = '0'.$text; } imagettftext ($image , $font['size'] , $font['angle'] , $font['x-offset'] , $font['y-offset'] , $font['color'] , $font['file'], $text ); ob_start(); imagegif($image); $frames[]=ob_get_contents(); $delays[]=$delay; $loops = 0; ob_end_clean(); } $now->modify('+1 second'); } //expire image instantly header( 'expires: sat, 26 jul 1997 05:00:00 gmt' ); header( 'last-modified: ' . gmdate( 'd, d m y h:i:s' ) . ' gmt' ); header( 'cache-control: no-store, no-cache, must-revalidate' ); header( 'cache-control: post-check=0, pre-check=0', false ); header( 'pragma: no-cache' ); $gif = new animatedgif($frames,$delays,$loops); $gif->display();`
the setinterval
function in javascript:
<script> setinterval(function () { .... every 1000 milliseconds .... }, 1000); </script>
you can update timer ... if wanting. change 1000 slower/faster wish.
Comments
Post a Comment