Updated Changing Avatar Script

August 13th, 2007, 11:22 am

I’ve updated my script that I previously blogged about that changes your avatar on different sites depending on what month it is.

Put the following to your website. In my example I’m naming it avatar.php

Add cases for the months you want to add or change. Change $avatar to the correct image. Change $type so that it is appropriate for the correct image. Gifs are image/gif. Jpgs are image/jpeg.

<?php

$month = strtolower(date('M'));

$avatar = '';
$type = '';
switch($month)
{
	case 'oct':
		$avatar = 'pumpkin.gif';
		$type = 'image/gif';
		break;

	case 'dec':
		$avatar = 'christmas-tree.gif';
		$type = 'image/gif';
		break;

	default:
		$avatar = 'elephant.gif';
		$type = 'image/gif';
		break;
}

header('Content-type: ' . $type);
readfile($avatar);

exit;

?>

In a .htaccess file add the following

RewriteRule avatar.jpg avatar.php
RewriteRule avatar.gif avatar.php

To use your dynamic avatar, you can link to either avatar.jpg or avatar.gif on your website. Preferably keep all of the image types the same.

If you have any questions, bugs or anything, let me know.

Leave a Reply