Random Avatar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
44X
Forum Newbie
Posts: 1
Joined: Sun Jul 24, 2005 7:20 pm

Random Avatar

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Even simpler:

Code: Select all

ln -s /path/to/generator.php  /path/to/pubwww/image.jpg
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

If you have shell access?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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'
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

It's really cool. Then again, that's subjective. I guess this would be more useful for say, a dynamic signature.
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post 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 ;) :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Post Reply