Random Avatar
Moderator: General Moderators
Random Avatar
On another board I saw a user who had an avatar that was randomly generated from a set of images, but the weird thing is that it was shown as a .jpg. It was like http://www.host.com/dir/avatar.jpg. How did he do that?
Also, you probably guessed this by now, but I'm a total noob to PHP.
Also, you probably guessed this by now, but I'm a total noob to PHP.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Well, that's a tricky question. Was the avatar always different when you viewed it? Possibly he used mod_rewrite on the Apache server to redirect the request for http://www.host.com/dir/avatar.jpg to, say, http://www.host.com/dir/avatar_script.php
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Even simpler:
Code: Select all
ln -s /path/to/generator.php /path/to/pubwww/image.jpg- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
If you have access to .htaccess ...
Example can be seen here.....
http://www.redmonkey.com/rmimages/forum ... /faces.jpg
Obviously the example uses 'faces.jpg' rather than 'avatar.jpg'
Code: Select all
<Files faces.jpg>
ForceType application/x-httpd-php
</Files>http://www.redmonkey.com/rmimages/forum ... /faces.jpg
Obviously the example uses 'faces.jpg' rather than 'avatar.jpg'
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- IceMetalPunk
- Forum Commoner
- Posts: 71
- Joined: Thu Jul 07, 2005 11:45 am
Although, you could always do it with JUST php, like so:
That would pick a random avatar image and display. Then all you need is an avatar that points to the PHP's URL.
-IMP

Code: Select all
<?php
$imgs[0]="avatar1.jpg";
$imgs[1]="avatar2.jpg";
$imgs[2]="avatar3.jpg";
$imgs[3]="avatar4.jpg";
$imgs[4]="avatar5.jpg";
$img=file_get_contents($imgs[rand(0,count($imgs))]);
header("Content-type: image/jpeg");
echo $img;
?>-IMP
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Yea, that is a script that will feed the server an image, but the the problem comes in when the forum software itself does not like you to like directly to php scripts. It checks for an image extension, therefor the above thread was discussing possible ways to trick the server into thinking your feeding it an image.