PHP Countdown with Image Rotation?

Soldato
Joined
14 Apr 2003
Posts
5,716
Location
Leicester
Hi all,

I am trying to get a countdown script working, which will then throw a different image up every time.

Here is the countdown script; haven't changed much in it, apart from the reference file for the image;

PHP:
<?

$month = 7; // Month of the countdown
$day = 1; // Day of the countdown
$year = 2004; // Year of the countdown

// mktime is the marked time,  and time() is the current time.
$target = mktime(0, 0, 0, $month, $day, $year);
$diff = $target - time();

$days = ($diff - ($diff % 86400)) / 86400;
$diff = $diff - ($days * 86400);
$hours = ($diff - ($diff % 3600)) / 3600;
$diff = $diff - ($hours * 3600);
$minutes = ($diff - ($diff % 60)) / 60;
$diff = $diff - ($minutes * 60);
$seconds = ($diff - ($diff % 1)) / 1;

$imgname = "countdown1.png";
$im = @imagecreatefrompng ($imgname);

//Here are some common color codes in case you want to change the colors.
//$white = imagecolorallocate ($im,  255,  255,  255);
//$blue = imagecolorallocate ($im,  0,  0,  255);
//$black = imagecolorallocate ($im, 0, 0, 0);
//$gray = imagecolorallocate ($im, 153, 153, 153);
//$red = imagecolorallocate ($im, 255, 0, 0);
//$orange = imagecolorallocate ($im,  255,  127,  36);

$background_color = imagecolorallocate ($im,  0,  0,  0);
$orange = imagecolorallocate ($im,  255,  127,  36);
$yellow = imagecolorallocate ($im,  247,  246,  201);
imagestring ($im,  2,  60,  5,   " Countdown to Half Life 2 Release:     Available from www.hl2empire.com",  $yellow);
imagestring ($im,  3,  65,  18,   "[ $days day(s) ] [ $hours hour(s) ] [ $minutes minute(s) ] [ $seconds second(s) ]",  $orange);
imagepng ($im);
imagedestroy ($im);
?>

Here is the script for countdown1.png (.htaccess rewrite); have also tried referencing as .php which doesn't make a difference

PHP:
<?php
$files = glob('{*.PNG,*.png,*.JPG,*.jpg,*.GIF,*.gif}', GLOB_BRACE);
readfile($files[array_rand($files)]);
?>

I was getting the following error messages in the log; now I am not getting anything!! :confused:

[21-Mar-2010 15:24:59] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/metalmay/public_html/sigs/countdown/test/countdown.php:22) in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 24
[21-Mar-2010 15:25:02] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/metalmay/public_html/sigs/countdown/test/countdown.php:22) in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 24
[21-Mar-2010 15:25:37] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 44
[21-Mar-2010 15:25:37] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 45
[21-Mar-2010 15:25:37] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 46
[21-Mar-2010 15:25:37] PHP Warning: imagestring(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 47
[21-Mar-2010 15:25:37] PHP Warning: imagestring(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 48
[21-Mar-2010 15:25:37] PHP Warning: imagepng(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 49
[21-Mar-2010 15:25:37] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/metalmay/public_html/sigs/countdown/test/countdown.php on line 50

File:
countdown.php


Any ideas? Really bugging me now!! :(

Edit: if I use the original script (which doesn't reference to the .php/.png image, it works...
 
Last edited:
Going to sound like a noob here (well I guess I am when it comes to PHP!!) Any ideas how I can do that?
 
Thanks :) - Really appreciated :D - Although it doesn't seem to be caching?

~Seems to be pulling the old file, which is random

index.php
 
Last edited:
Back
Top Bottom