How To Create A Random Avatar - (Extended ARticle)

STEP 1 - Pre-requisites (downloads and installs)

editor-

download and install an editor that allows you to save files as .php
i suggest notepad++

you can get it here: http://notepad-plus.sourceforge.net/uk/site.htm

follow the installers instructions to install notepad++

host -

you will need a host that is php capable and is fairly up to date. php4 is sufficient.
i use a host that costs about 6$ a month.

you can find it here: www.startlogic.com

if you require a free host that is capable of running php scripts please visit: http://www.free-webhosts.com/free-php-webhosting.php

ftp client -
if your host has ftp capabilities than you can use one to upload your folders, scripts, and images.

i recommend filezilla: http://filezilla-project.org/download.php?type=client

please be sure to download and install the CLIENT version, which i have linked you to.

follow the installers instructions to install filezilla ftp client

setting up filezilla to upload files to your host -

click on the open site manager button
Image

1. click on new site
2. enter the name of your host. its the url that you would use to link to your site.
-i use www.startlogic.com but mine site name is legendkpr.startlogic.com. so i would use my site url.
-you can leave the port blank. it may cause problems if you dont know what port your hosts server uses
3. use ftp - file transfer protocol
4. use standard login.
5. this is where youre username goes. the name you use to login to your host.
6. password. same as the password you use to login to your host.
Image

you can now click ok, and connect to your host. if you followed the steps correctly it should show a bunch of text and information while its connecting and then show the directories of your computer and youre webhost.

local files are your computers files and remote files are your hosts files.

STEP 2 - setup directories

create a folder and call it something like randomavatar (thats what i am using in this article)

inside this folder, create another folder called images (thats what i am using in this article)

STEP 3 - add images

inside the images folder, put all the images you want named with numbers from 0.

for example: 0.jpg , 1.jpg , 2.jpg , 3.jpg

(please note that all the images must be of the same file extension and that because the script is case sensative that the extensoins are all in lowercase)

because i wrote this script myself it supports any number of images so add as many as you want. just be sure they are in sequential order and no numbers are repeated and no numbers are skipped.

in the future i will write a script that allows for variable types of images, jpg gif png etc.

STEP 4 - the php script

the script is suprisingly the easiest part here

open up notepad++ and paste the following script.
save this script as randomavatarscript.php and put it in the randomavatar folder.


<?php

header("Location: http://www.yourhost.com/randomavatar/images/". rand(0,$_GET['max']). ".jpg");

?>



of course replace the first part of the location to the actual name of your host and make sure the url path to randomavatar is correct as well.

if you use .png .gif etc. then replace .jpg with that file extension.

STEP 5

upload the folder to your host. (some hosts wont let you upload folders using an ftp so you will have to create the folders and upload the script and images manually)

in filezilla simply locate your randomavatar folder, navigate to the folder you want to upload it to on your host, right click and select upload.

FINAL!

put the link to the randomavatarscript.php as your avatar instead of an image link and viola! random avatars for all!!

example:

http://www.yourhost.com/ramdomavatar/randomavatarscript.php?max=5



obviously replace 'yourhost' and make sure the url path is correct.

the ?max=5 is for setting how many pictures there are in the images folder. the script randomly pics a number from 0 to max and displays the corresponding image.

set this to the largest numbered image in the images folder to use all of them

if you have an questions or need further help, feel free to pm me.