Dynamic Avatar depending on the Month
October 3rd, 2005, 08:17 pm
If your like me and want to have a different avatar that deals with the holidays then you’ll like this script which can be used to change your avatar to a different one each month. You can see this script working on my account on phpBB.com. Of course if you want to see it change, you’ll have to wait until the new month
Updated version of this script 13 Aug. 2007.
Part 1 - the PHP Code
Copy and paste the code below into a file on your website. I’d recommend naming the file avatar.php because of part two. To add or change months, add or alter the case and use the three letter abbreviation for the month (January is jan, March = mar, etc) in lowercase. What is under the default case is what will be shown when you haven’t specified an image for that month. For the images, change the part after location within the location function of each case.
[php]< ?php
$month = strtolower(date('M'));
switch($month)
{
case 'oct':
header('location: image1.gif');
break;
case 'nov':
header('location: image2.jpg');
break;
case 'dec':
header('location: image3.gif');
break;
default:
header('location: default_image.gif');
break;
}
exit;
?>[/php]
Part 2 - .htaccess
A lot of sites only allow you to put files that are image extensions as your avatar and not .php files. This is because of security so we’ll have to use .htaccess to get around this. Either place the following in your existing .htaccess file or create a new one. This .htaccess assumes that you named the PHP file from part 1 as avatar.php and that you put avatar.jpg in the spot where put your avatar.
# you only need RewriteEngine on once within each
# .htaccess file so if you already have it, you don't need to
# put it again
RewriteEngine on
# change avatar.jpg to what you use on the site where
# you are putting your avatar. change avatar.php to
# whatever you named the php file
RewriteRule avatar.jpg avatar.php
If you have any questions or problems, post a comment and I’ll try to help you out. Enjoy!








