Random signature image
From PunBB Resource Wiki
This little script allows you to have a random signature on any forum supporting the [img] BBCode. Note that your webhost (not the forum's) has to support PHP.
Contents |
[edit]
The code
Make a new PHP file, sig.php.
Insert this code:
<?php $directory = dir('.') ; $images = Array() ; $filetypes = Array() ; while (false !== ($item = $directory->read())) { if(false === strpos($item, '.')) continue ; $item_ext = explode('.', $item) ; $item_ext = $item_ext[count($item_ext) - 1] ; switch($item_ext) { case 'jpeg': case 'jpg': $filetypes[] = 'image/jpeg' ; $images[] = $item ; break ; case 'gif': $filetypes[] = 'image/gif' ; $images[] = $item ; break ; case 'png': $filetypes[] = 'image/png' ; $images[] = $item ; break ; } } $directory->close() ; $rand = mt_rand(0, count($images) - 1) ; $image = $images[$rand] ; $type = $filetypes[$rand] ; header("Content-type: $type") ; if( false !== ( $length = filesize($image) ) ) { header("Content-length: $length") ; } header('Pragma: no-cache') ; header('Cache-control: no-cache') ; header('Expires: Thu, 01 Dec 1994 16:00:00 GMT') ; //straight out of the RFC :) readfile($image) ; ?>
This will include all the images in the same directory as the script.
[edit]
Usage
Go to your signature settings, and insert this:
[img]http://www.yourhost.com/yourdir/filename.php[/img]
[edit]
Workarounds if PHP extention is not supported in signature
[edit]
Fake extension method
Append a bogus image "file" to your PHP call:
[img]http://www.yourhost.com/yourdir/filename.php/bogus.png[/img]
This should work in most situations.
[edit]
Folder extension method
Change the name of the folder your script is in to something like "sig.png". Then name your script 'index.php'. Call it with:
[img]http://www.yourhost.com/sig.png[/img]
Created by Elbekko 17:40, 2 July 2006 (GMT), rewritten to be much less processor-intensive by Thetorpedodog 17:20, 14 July 2006 (GMT)

