Posted for Archival
The SMALLEST Random Image Generator
The 26 Line Randosig
Supported Web Host(s):
Any Web Host that supports PHP 4.3 or better (most do).
If you need a free host, we recommend
http://www.hostinganime.com
We've talked about a spell checker for IE, and we've shown you some great tools for FireFox including a right-click bbcode context menu. Probably one of the biggest questions asked in Questions & Feedback is about random sig generators. A different image every time you refresh the page. Undoubtedly, one of the most popular is Rome, but the Toolbox is all about self-empowerment. And so, this time, we are going to show you a 26 line file that will let you host your own random sig generator!
Mandatory Background Information
We're going to be working with PHP, a web based scripting language. If your host supports PHP, they will say so, and they will advertise it. Sites such as geocities and angelfire do not have php based hosting. Freewebs does not have PHP hosting. The only currently known free provider that has php based hosting is hostinganime.com (see link at top). We are not going to make you code anything in this thing either, but we are going to have you make a file and upload it. Here are some very basic rules:
- You need a text editor (Notepad, Textpad, Simpletext, KWrite, etc)
- You need a way to put the file we make on your host (FTP)
If you have both of these things, we are ready to begin. You will also want some images. (gif, jpg. or png)
Step 1: rand.php and uploading
No joke, this will be the hardest step. Open a text editor from the above list, and paste the following code, from <?PHP to the final ?>
<?PHP
//////////////////////////////////////////////////////////////////
// Your Own Personal "RandoSig"
// Done for the Daily Post: Your authoritative QnF paper!
// Code by Jakob (Jakobo). Public Domain.
//////////////////////////////////////////////////////////////////
$files = Array()
if (is_dir("./")) {
if ($dh = opendir("./")) {
while (($file = readdir($dh)) !== false) {
if($file != "." &&
$file != ".." &&
$file != "" &&
$file != "rand.php") { $files[] = $file; }
}
closedir($dh)
}
}
$random_file = (rand()%sizeof($files))
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT")
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT")
header("Cache-Control: no-store, no-cache, must-revalidate")
header("Cache-Control: post-check=0, pre-check=0", false)
header("Pragma: no-cache")
if(substr($files[$random_file], -3) == "jpg") {
header("Content-type: image/jpeg")
} elseif(substr($files[$random_file], -3) == "gif") {
header("Content-type: image/gif")
} elseif(substr($files[$random_file], -3) == "png") {
header("Content-type: image/png")
} else { header("Content-type: text/plain")
echo "Image Error, could not load (".$random_file.")".
$files[$random_file] print_r($files) }
@readfile($files[$random_file])
?>
Before you say it, yes, it is 35 lines, not 26. The longer lines were broken up for readability (and so they would copy correctly). Now that you have this all pasted in, save the file as rand.php somewhere you can find it (I recommend the desktop). Then, upload it into a directory on your web server.
While you are uploading, upload the images you would like to have randomized as well. Here's a picture of my directory:
Your Sig's Directory[color=white]
<center>

5 image files and the "rand.php" file.
For this to work right, remember not to put anything other than images and rand.php into this directory!</center>
Step 2: Using
See, I told you that would be the hard part. If you uploaded your rand.php and your images, you are done. Yes, done. To call the random sig, simply create an img tag pointing to rand.php. For example:
[img]http://gaia.felocity.org/gavsim/rand.php[/img]
<center>

</center>
Drop that image tag into your sig, and you're done! And you didn't really have to lift a finger.
You know it was good for you too... discuss it!