• Log in or sign up for an account here: https://www.sythe.org/login

[PHP][snippet] Random Dynamic Forum Signature

Arizane

Newcomer
Joined
Jul 19, 2008
Sythe Gold
0
Messages
2
[PHP][snippet] Random Dynamic Forum Signature
This code well let you have a random dynamic image in your forum signature.

PHP:
<?php
$folder = '';

$exts = 'jpg jpeg png gif';

$files = array(); $i = -1;
if ('' == $folder) $folder = './';

$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
   foreach($exts as $ext) {
	   if (preg_match('/\.'.$ext.'$/i', $file, $test)) {
		   $files[] = $file; // it's good
		   ++$i;
		   }
	   }
   }
closedir($handle);
mt_srand((double)microtime()*1000000);
$rand = mt_rand(0, $i); // $i was incremented as we went along

$rimg = $files[$rand];

header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($fn)).' GMT', true, 200);
header('Content-Length: '.filesize($rimg));
header('Content-Type: image/png');
print file_get_contents($rimg);
?>
This basically loads all .png file types into it and outputs it randomly so if you load the page. it might display image1.png then if you reload it, it will display a differnt image say image3.png or whatever.

Currently this is used for png file types but that can be easily changed by changing
PHP:
header('Content-Type: image/png');
to something like
PHP:
header('Content-Type: image/gif');
To see it in use just look at my signiture or go to http://arizanegamesltd.vndv.com/index.php

To use it just use.
Remember to change it to your website and the name of the file u saved the php page as.

Originate on Cruels.Net
http://cruels.net/index.php?showtopic=7092&hl=

Enjoy ^_^ Ill be posting more stuff soon.
 
[PHP][snippet] Random Dynamic Forum Signature
[mod]In the future, when posting PHP, use the [ php ] tag. Otherwise, if you use [ code ] you fuck up the template somehow and kill your thread.[/mod]
 
[PHP][snippet] Random Dynamic Forum Signature
[mod]In the future, when posting PHP, use the [ php ] tag. Otherwise, if you use [ code ] you fuck up the template somehow and kill your thread.[/mod]

well thats good to know... thanks.. D:
 
[PHP][snippet] Random Dynamic Forum Signature
Instead of:
PHP:
header('Content-Type: image/png');

You could try:
PHP:
$size = getimagesize($rimg);
header('Content-Type: ' . $size['mime']);

And maybe you could use glob instead of the open_dir and read_dir things.
 
[PHP][snippet] Random Dynamic Forum Signature
Dynamic PHP images are lotsa fun =O

My sig is dynamic >_>
 
[PHP][snippet] Random Dynamic Forum Signature
I really should learn how to do this. It would be fun, and quite useful.
 
[PHP][snippet] Random Dynamic Forum Signature
Using Stephen (AADude)'s function..

Usage: All your files named with ONLY numbers, in order, 1 through whatever.

Could have used GLOB but I wrote this a while ago and didn't know what it was till a bit ago.

Cant use php tags, they fuck up my code.

God damnit. Fuck your tags. http://supahfly.net/sig/src.php there is the source code Ive been trying to post for 10 minutes. They all screw up my code. -.-
 
[PHP][snippet] Random Dynamic Forum Signature
Also since I wrote that awhile ago @ supah, I would suggest to integrate getimagesize instead of the separate headers.
 
Runescape Gamblingrunescape gambling
Back
Top