OZONE Asylum
FAQ
Master Suho's PHP Sig Rotator
This page's ID:
5689
Search
QuickChanges
Forums
FAQ
Archives
Register
You are editing "Master Suho's PHP Sig Rotator"
Who can edit an FAQ?
Anyone registered may edit an FAQ.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
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: [img]http://liminality.org/asylum/sigs/[/img] 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 [url=http://www.ozoneasylum.com/Forum14/HTML/001290.html]May sig contest[/url]. 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 [b]between[/b] 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 [i]recommend[/i] updating to this code. It probably won\'t make much of a difference, but it won\'t hurt, either.) [b]Note:[/b] If you are having problems getting the script to work, please see the [b]Alternate Version[/b] 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[] function buildimagearray($dir) { while (false !== ($file = readdir($dir))) { if (!is_dir($file) && getimagesize($file)) { $list[] = $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[$sig]); $fp = fopen($list[$sig], \"rb\"); if ($size && $fp) { header(\"Content-type: {$size[\'mime\']}\"); fpassthru($fp); exit; } } ?>[/code] ------------------------------------------------------------------------- [b]Alternate Version[/b] Modification were made to the code in response to a problem bodhi had (discussed [url=http://www.ozoneasylum.com/Forum14/HTML/001454.html]here[/url]). 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[] function buildimagearray($dir) { while (false !== ($file = readdir($dir))) { if (!is_dir($file) && getimagesize($file)) { $list[] = $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[$sig]); $fp = fopen($list[$sig], \"rb\"); if ($size && $fp) { header(\"Content-type: {$size[\'mime\']}\"); fpassthru($fp); exit; } } ?>[/code] ------------------------------------------------------------------------- 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. [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Tyberius+Prime]Tyberius Prime [/url] on Wed 21-May-2003)[/i][/small] Actually, it [i]is[/i] filtered to contain only images... that\'s what the getimagesize() does. Yes, I realize it grabs [i]all[/i] 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. [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Suho1004]Suho1004 [/url] on Wed 28-May-2003)[/i][/small] 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. [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Suho1004]Suho1004 [/url] on Thu 29-May-2003)[/i][/small] (Added five new sigs to the mix. See above for details.) [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Suho1004]Suho1004 [/url] on Mon 09-Jun-2003)[/i][/small] ---------------------- 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 [url=http://www.max.co.yu/ozone/sig.pl.txt]here[/url] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Tyberius+Prime]Tyberius Prime [/url] on Fri 20-Jun-2003)[/i][/small] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Suho1004]Suho1004 [/url] on Sun 26-Oct-2003)[/i][/small] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=docilebob]docilebob [/url] on Fri 02-Apr-2004)[/i][/small] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Suho1004]Suho1004 [/url] on Fri 02-Apr-2004)[/i][/small] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Suho1004]Suho1004 [/url] on Sat 03-Apr-2004)[/i][/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »