MyBB Community Forums

Full Version: Nathan Malcolm's random avatar trick
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So does anyone know how Nathan Malcolm does that random avatar trick. You know that when you view him in a post or profile his avatar keeps changing.
Host a script on your own server that redirects/outputs a random image each time it is loaded.
Set your avatar to point to that script.

I used to use this script, it finds all PNG and GIF images in the avatars folder and redirects to a random one. It also sends a cache header so that users will only see the avatar change once every 30 minutes.
<?php
$folder = 'avatars/';
$settings['img_ext'] = array('.png','.gif');
$flist = array();
foreach($settings['img_ext'] as $ext)
{
    $tmp = glob($folder.'*'.$ext);
    if (is_array($tmp))
    {
    	$flist = array_merge($flist,$tmp);
    }
}
$src = $flist[array_rand($flist)];

$seconds_to_cache = 1800;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");
header('Location:'.$src);
exit();
?>
Hmm thanks , i will put this in my code box.
(2014-02-19, 02:33 PM)Paul H. Wrote: [ -> ]http://community.mybb.com/thread-151014.html

thanks Paul H. ^
I had this years ago Sad
Matt has this before it was cool. You so hipster you... ^_^