Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
Asylum General
Who are the inmates?
Suho1004

Master Suho's PHP Sig Rotator Pages that link to <a href="http://ozoneasylum.com/backlink?for=5689" title="Pages that link to Master Suho&amp;#039;s PHP Sig Rotator" rel="nofollow" >Master Suho&#039;s PHP Sig Rotator\

To make things easier on inmates who would like to rotate their sigs, here is a simple PHP script that will do the job for you. First, an example:



This is the sig rotator at work, displaying every sig I\'ve ever made for the Asylum* (be warned, there\'s some pretty bad stuff in here, but there\'s also a sig contest winner ;-)). Refresh the page to see a new sig (in IE6 I often have to do a hard refresh (CTRL-F5) to get the script to run again).

-----
* Every sig, that is, except my fortune cookie sig, which is actually a dynamically generated image, not a rotated sig. I have now also added five sigs made for me in the May sig contest. Thanks to CPrompt, Dufty, the Emperor, Raptor, and Ruski.
-----

And now, on to the code. Installation consists of merely saving this code as a .PHP file in your sig directory--no changes are needed. Just copy and paste everything between the dotted lines.

(Note: I have removed version 1.0 of the sig rotator code. That version should still run properly, but there were things that I could have done better, and I did them in version 2.0. If you have the old code, I would recommend updating to this code. It probably won\'t make much of a difference, but it won\'t hurt, either.)

Note: If you are having problems getting the script to work, please see the Alternate Version below. If that doesn\'t work either, send me an e-mail and I\'ll be glad to help if I can.

And I would also appreciate it if this page was left as is... please post any modifications or amendments as subtopics (like quisja\'s modified version). Thanks.

-------------------------------------------------------------------------

code:
<?php
//////////////////////////////////////////////////////////////////////
/* Suho1004\'s PHP Sig Rotator V2.0 */
/* */
/* This script takes an inventory of all image files in a directory */
/* and displays one at random. All you need to do is save this code */
/* in a directory that contains your images (name it what you will, */
/* but make sure it has a \".php\" extension). Then just link to this */
/* script to get your random image. */
/* */
/* I would recommend naming this file \"index.php,\" and then you can */
/* just link to the directory itself (like I do in my example). */
/* */
/* Once you\'ve read these instructions, feel free to delete them to */
/* cut down on the file size. I claim no rights to this code, which */
/* means you can do whatever you like with it. Have fun. :-) */
/* */
/* Thanks to TP for the gentle nudging... */
//////////////////////////////////////////////////////////////////////

if ($dir = opendir(\".\"))
{
$list = buildimagearray($dir);
displayrandomimage($list);
}

// This function reads all the files in the current directory and adds all image files to the array $list&#91;&#93;
function buildimagearray($dir)
{
while (false !== ($file = readdir($dir)))
{
if (!is_dir($file) && getimagesize($file))
{
$list&#91;&#93; = $file;
}
}
return $list;
}

// This function selects a random image, determines the mime type, opens the file for reading,
// and then outputs the image
function displayrandomimage($list)
{
srand ((double) microtime() * 10000000);
$sig = array_rand ($list);

$size = getimagesize ($list&#91;$sig&#93;);
$fp = fopen($list&#91;$sig&#93;, \"rb\");

if ($size && $fp)
{
header(\"Content-type: {$size&#91;\'mime\'&#93;}\");
fpassthru($fp);
exit;
}
}
?>


-------------------------------------------------------------------------

Alternate Version

Modification were made to the code in response to a problem bodhi had (discussed here). She is using PHP version 4.2.2., and array_rand wasn\'t working properly. I\'m not sure why, but I discovered that a simple rand() works instead.

I would still recommend using the original code (version 2.0 above), but if you run into the same problems as bodhi (ie, the random function doesn\'t work and the code only displays the first sig in the directory), you might want to give this code a try:

-------------------------------------------------------------------------

code:
<?php
//////////////////////////////////////////////////////////////////////
/* Suho1004\'s PHP Sig Rotator V2.0 */
/* */
/* This script takes an inventory of all image files in a directory */
/* and displays one at random. All you need to do is save this code */
/* in a directory that contains your images (name it what you will, */
/* but make sure it has a \".php\" extension). Then just link to this */
/* script to get your random image. */
/* */
/* I would recommend naming this file \"index.php,\" and then you can */
/* just link to the directory itself (like I do in my example). */
/* */
/* Once you\'ve read these instructions, feel free to delete them to */
/* cut down on the file size. I claim no rights to this code, which */
/* means you can do whatever you like with it. Have fun. :-) */
/* */
/* Thanks to TP for the gentle nudging... */
//////////////////////////////////////////////////////////////////////

if ($dir = opendir(\".\"))
{
$list = buildimagearray($dir);
displayrandomimage($list);
}

// This function reads all the files in the current directory and adds all image files to the array $list&#91;&#93;
function buildimagearray($dir)
{
while (false !== ($file = readdir($dir)))
{
if (!is_dir($file) && getimagesize($file))
{
$list&#91;&#93; = $file;
}
}
return $list;
}

// This function selects a random image, determines the mime type, opens the file for reading,
// and then outputs the image
function displayrandomimage($list)
{
$maxrand = sizeof($list)-1;
$sig = rand(0, $maxrand);

$size = getimagesize ($list&#91;$sig&#93;);
$fp = fopen($list&#91;$sig&#93;, \"rb\");

if ($size && $fp)
{
header(\"Content-type: {$size&#91;\'mime\'&#93;}\");
fpassthru($fp);
exit;
}
}
?>


-------------------------------------------------------------------------

Notes: You should probably filter your directory list to contain only images... by filename, probably.
Oh, and rand() had to be initialized with srand() in older php versions.

(Edited by: Tyberius Prime on Wed 21-May-2003)

Actually, it is filtered to contain only images... that\'s what the getimagesize() does. Yes, I realize it grabs all images, even some that may not be web-compatible, but the goal was to get the code as compact as possible, and if someone is going to go sticking .tifs in their sig folder then that\'s their problem. Harsh, perhaps, but that\'s just the way it is ;-).

As for the seeding, I am running an older version of PHP, but it still seems to work. Not sure what\'s up with that. I will change things over to array_rand() when I get the chance, though.

(Edited by: Suho1004 on Wed 28-May-2003)

Cleaned up the page by deleting everything but the latest version of the code--the old stuff was just clutter. The new code seeds the random number generator (hopefully producing better results?) and also uses array_rand() to get the random keys.

(Edited by: Suho1004 on Thu 29-May-2003)

(Added five new sigs to the mix. See above for details.)

(Edited by: Suho1004 on Mon 09-Jun-2003)

----------------------
There are other sig rotators, most notably maybe one of mr.max\'s (he\'s written serveral, but he\'s not very active nowadays).
You can find it here

(Edited by: Tyberius Prime on Fri 20-Jun-2003)

(Edited by: Suho1004 on Sun 26-Oct-2003)

(Edited by: docilebob on Fri 02-Apr-2004)

(Edited by: Suho1004 on Fri 02-Apr-2004)

(Edited by: Suho1004 on Sat 03-Apr-2004)

« BackwardsOnwards »

Show Forum Drop Down Menu