Welcome to Gaia! ::

Reply How-To Guides Guild
How To: Make a Random Sig [Alternate Version]

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200
PostPosted: Thu Sep 29, 2005 10:54 am


User Image - Blocked by "Display Image" Settings. Click to show.
~ By Lord-of-the-flies ~

User Image


Welcome to the random signature tutorial. This tutorial will not only provide you with information on how to build two types of simple server-side image randomizers, but also allow you access to the free software "myRAND" with full support. For your convenience, I have made an effort to break down each portion of the tutorial to it's simplest possible form. If you have any questions reguarding this tutorial, please PM me with your question, and I will edit the tutorial to better fit your needs. Thank you.

User Image - Blocked by "Display Image" Settings. Click to show.
PostPosted: Thu Sep 29, 2005 11:04 am


User Image - Blocked by "Display Image" Settings. Click to show.
There are a few different varieties of random imagery, however they all have the same function: pick an image out at random and display it. Unfortunately, due to restrictions of Gaia, and most phpBB boards, one can not use a client side script to generate random images, so we have to refer to the server-side scripting - In this case, we will be using PHP. The tutorials I have posted will make it possible to display any type of image, though it is strongly recommended that you do not use the BMP format. If you have any questions, feel free to PM me or post on the thread - I'll get back to you with the answers as soon as I can. Happy randomizing!

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200
PostPosted: Thu Sep 29, 2005 11:29 am


PostPosted: Thu Sep 29, 2005 11:33 am


User Image - Blocked by "Display Image" Settings. Click to show.
Because of the nature of the scripts in this tutorial (being PHP, that is), we must find a host that can support it. There are any number of hosts out there that will support PHP on their servers, but because I know that it's better to have a list of hosts (I know I wouldn't want to search), I'm going to provide you with a few quality PHP web hosts.

|| Tripod UK
|| Host Ultra
|| My Site Space
|| Ripway
|| FBHosting

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200
PostPosted: Thu Sep 29, 2005 11:36 am


[ Message temporarily off-line ]
PostPosted: Thu Sep 29, 2005 12:05 pm


[ Message temporarily off-line ]

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200
PostPosted: Thu Sep 29, 2005 12:05 pm


[ Message temporarily off-line ]
PostPosted: Thu Sep 29, 2005 12:09 pm


User Image - Blocked by "Display Image" Settings. Click to show.
This portion of the tutorial is designed to help you understand the PHP code put into the directory and array methods in this tutorial. This is not a required reading to make the image randomizer work, but instead it is designed to help you learn. Note that this portion assumes that you have some basic programming experience in one or more varibable language.

First, we'll take a look into the variables of this script. For those new to PHP, variables are simple assigned sets of characters that stand for something else. In PHP, variables are indicated with a dollar sign prefixed upon the variable name.
$files

This works just like it would in any other programming language, and you simply assign the variable using an equal sign, followed by the variable in question.

Directory Method
Next we look into the function assigned to the $files variable: scandir().
scandir("images")

Scandir() is a function that's been around since PHP 1.0 or so. This function will literally scan a directory and return it's contents as an array. This makes it possible to read file names from a directory without having to first open it, read it, loop it, etc. Very handy indeed. Inside the parenthesis, there is the word "images" encapsulated by quotation marks - This tells the function what directory to read and return.


Now we move on to count().
count($files)

Count() tells us exactly how many objects are inside an array. In this instance, we are counting the objects in the scandir() returned array, which was assigned to $files.

Directory Method
if(count($files) > 2){

The "if" statement, followed by a requirement in parenthesis, makes sure the code inside the brackets is executed only if the statement is true. In this case, we will only execute the code in the brackets provided the number of items in the directory is greater than two. The reason that we look for more than two is because, with each directory there comes two pre-defined statements which lead to a higher directory. Because these are not actual files, we don't want to include them.

Directory Method
$n = rand(2,(count($files)-1))

Rand(a,b) provides us with a random whole number between "a" and "b". Again, we exclude the first two variables (the non-files) by placing "2" as our "a".

Array Method
$n = rand(0,(count($files)-1))

Rand(a,b) provides us with a random whole number between "a" and "b". To start us off, we place "0" in the "a" position to hold the base of the array,

And our "b" will be the number of files minus one. Why the minus one? I'll explain that shortly.

$files[$n]

$files is our array, and $n is our random number. Arrays automatically assign each object in itself a number, starting at "0", and each object can be called though the assigned variable using a square bracket and the number. Because arrays start at zero, we have to compensate for that additional number we would get from the actual number of items, thusly we subtract one from our random number.
Directory Method
In all instances of a directory scan (using the $files variable for example), the first two variables will be:
$files[0] = "."
$files[1] = ".."

This makes $files[2] and higher files in that directory.

header("location: images/$files[$n]")

Here's the most important portion of the file, the header(). Headers are kinda tricky when programming, but because this script is tiny, it shouldn't hurt too much. Header basically re-defines the program after receiving variables, making the files seem like another file in this case. "location: " tells the header that this file will act as the files that it's being assigned to, and "images/$files[$n]" fills in where it is supposed to go.

Directory Method
}

This ends the code that would be executed if the statement is true.

Now, what if the statement actually wasn't true? What if we had no files in that directory? Well, in that case, we have the "Else" statement ready.
else echo "No images avalible";

"Else" follows after a "If" statement, allowing the script something to do if we can't do the first. In this case, we "echo" the sentence "No images avalible." What exactly does echo do? It prints out words on the screen for us to see. Simple, no?


Aaannnndd... that's it! We're done with understanding the code!

Lord-of-the-flies

Wealthy Capitalist

5,750 Points
  • Millionaire 200
  • Entrepreneur 150
  • Money Never Sleeps 200

Sweet n Leo
Crew

Sparkly Phantom

8,650 Points
  • Elocutionist 200
  • Person of Interest 200
  • Hygienic 200
PostPosted: Wed Dec 07, 2005 2:09 am


I never said thanks for this guide, so I will now ^_^

Totally appreciated!
PostPosted: Mon Jul 31, 2006 8:31 am


Lord-of-the-flies

COULD YOU HOST YOUR FILES ON A DIFERENT HOST BECAUSE WHEN YOU GO TO THE LINK IT TAKES YOU TO A A PAGE WITH A BUNCH OF ADS

soad524

Reply
How-To Guides Guild

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum