Page 1 of 1

Random Avatar

Posted: Sun Jul 24, 2005 7:32 pm
by 44X
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.

Posted: Sun Jul 24, 2005 7:43 pm
by Ambush Commander
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

Posted: Sun Jul 24, 2005 7:44 pm
by Todd_Z
you can change how extensions are executed by the server. He has the .jpg files executed as a .php - Im thinking in the httpd.conf file maybe... help me out guys

Posted: Sun Jul 24, 2005 7:46 pm
by Ambush Commander
Yeah, but the problem with having binary files executed as PHP (which by the way, is possible), is that one of those days you'll get a binary file that has <?php in it. Plus, it's incredibly wasteful.

A simple internal server redirect will do.

Posted: Sun Jul 24, 2005 8:05 pm
by timvw
Even simpler:

Code: Select all

ln -s /path/to/generator.php  /path/to/pubwww/image.jpg

Posted: Sun Jul 24, 2005 8:08 pm
by Ambush Commander
If you have shell access?

Posted: Sun Jul 24, 2005 8:13 pm
by redmonkey
If you have access to .htaccess ...

Code: Select all

<Files faces.jpg>
ForceType application/x-httpd-php
</Files>
Example can be seen here.....

http://www.redmonkey.com/rmimages/forum ... /faces.jpg

Obviously the example uses 'faces.jpg' rather than 'avatar.jpg'

Posted: Mon Jul 25, 2005 2:23 am
by Chris Corbyn
Ambush Commander wrote:If you have shell access?
And if Apache has it turned on... ;)

One thing I don't get though... what's the point in a "random" avatar? I thought you're avatar was something to identify you :?

Posted: Mon Jul 25, 2005 11:10 am
by Ambush Commander
It's really cool. Then again, that's subjective. I guess this would be more useful for say, a dynamic signature.

Posted: Mon Jul 25, 2005 12:20 pm
by IceMetalPunk
Although, you could always do it with JUST php, like so:

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;
?>
That would pick a random avatar image and display. Then all you need is an avatar that points to the PHP's URL.

-IMP ;) :)

Posted: Mon Jul 25, 2005 12:54 pm
by John Cartwright
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.