Jump to content

PHP code to switch out banner by month?


linkjg

Recommended Posts

Hello!

 

My personal website has a new banner each month for holiday themes. (I have a Christmas and Halloween banner, etc)

 

Right now, I have to manually switch out the picture each month.

 

Is there a free PHP code that would switch out the banner for me?  ???

 

Thanks for your help!

Link to comment
https://forums.phpfreaks.com/topic/50263-php-code-to-switch-out-banner-by-month/
Share on other sites

switch the link to the image to a php script with an image header and then on preset dates the script can point to different files

see below

 

 

EDIT: call this image.php and replace your banner.jpg with image.php

<?php
function LoadJpeg($imgname)
{
    $im = @imagecreatefromjpeg($imgname); /* Attempt to open */
    if (!$im) { /* See if it failed */
        $im  = imagecreatetruecolor(150, 30); /* Create a black image */
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an errmsg */
        imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
    }
    return $im;
}
header("Content-Type: image/jpeg");
$today = getdate();
switch($today['mon'])
{
default:
case 1:
$img = LoadJpeg("Jan.image.jpg");
break;
case 2:
$img = LoadJpeg("Feb.image.jpg");
break;
case 12:
$img = LoadJpeg("xmas.image.jpg");
break;
}
imagejpeg($img);
?> 

 

its a start :)

 

 

**UNTESTED

 

i guess this is free :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.