x404.co.uk
http://www.x404.co.uk/forum/

Random Avatars - how it’s done
http://www.x404.co.uk/forum/viewtopic.php?f=3&t=36
Page 1 of 1

Author:  paulzolo [ Fri Apr 24, 2009 10:02 am ]
Post subject:  Random Avatars - how it’s done

I’ve copied this from the old forum, as people like to know.

Folk ask me from time to time how I get my avatar to change. I get stopped regularly in the street and asked that question. I laugh when people think I do it manually. I'm just too lazy to oblige you to this level.

I do, however, employ some server based trickery.

So, let’s take a call from one of our listeners.....
bally199 wrote:
Paulzolo, tell us the secret!


bally199 is labouring under the delusion that there is some secret involved. He's also laughing. Poor fool. Must be the meths....

Well, bally199999, you can tell servers that files are to be treated in certain ways. A file ending in .gif or .jpg does not necessarily have to be an image.

You see, index.jpg is not really an image file.

In the case of the file for my avatar, it's a .php file. Instead of .php at the end of the file name, I use .jpg. This means the PHPBB and others accepts the URL of the file.

I use a .htaccess file to tell the server to treat the file as a .php file (which is what it is anyway). To not do this, the server will think it's a graphic and will serve up the file with all the appropriate headers. We don’t want this - yet. The server seems index.gif, and runs it as php.

Now, bally19999999999999999999, the fun can start.

The php scans the folder, looks for all images therein (apart from itself) and picks one at random. It then throws the correct headers (so the server and your browser treat the file as a graphic) and the bytestream (the actual numbers which make up the image you want to show) at the browser.

The result is a random image:
http://www.worldofpaul.com/avatars2/index.jpg <-- click the URL.

If you refresh the browser, the image will change. But it's still index.jpg.

I hope that bally199999999999 and others find this answer enlightening and useful.

Does this help?

Author:  brataccas [ Mon Jan 14, 2013 12:27 pm ]
Post subject:  Re: Random Avatars - how it’s done

Does this eccentric trick work on windows XP or do I need a mac? no server required?

Author:  jonlumb [ Mon Jan 14, 2013 12:39 pm ]
Post subject:  Re: Random Avatars - how it’s done

brataccas wrote:
Does this eccentric trick work on windows XP or do I need a mac? no server required?


It's something the Masons do for you if you ask them nicely.

Author:  EddArmitage [ Mon Jan 14, 2013 12:50 pm ]
Post subject:  Re: Random Avatars - how it’s done

brataccas wrote:
Does this eccentric trick work on windows XP or do I need a mac? no server required?

It's done server-side so what type of PC you use doesn't really come in to it.

Author:  paulzolo [ Mon Jan 14, 2013 12:59 pm ]
Post subject:  Re: Random Avatars - how it’s done

Yup - all on the server side driven. It’s a Linux machine, but what it does - stream the data from a randomly chosen file to your browser could be done on a Windows IIS server if you knew someone handy with ASP. I expect even Windows NT 2000 could do this. ;)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/