• 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
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.
 
Wait, do you not have an Archer rank?
Doge
Smashing
Why is there BACON in the SOAP!?
Literally nothing
I saw Matthew
Live Free or Die
Cool Kid
Poképedia
[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]
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
[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:
 
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.
 
Wait, do you not have an Archer rank?
Doge
Smashing
Why is there BACON in the SOAP!?
Literally nothing
I saw Matthew
Live Free or Die
Cool Kid
Poképedia
Dynamic PHP images are lotsa fun =O

My sig is dynamic >_>
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
I really should learn how to do this. It would be fun, and quite useful.
 
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. -.-
 
Also since I wrote that awhile ago @ supah, I would suggest to integrate getimagesize instead of the separate headers.
 
Runescape Gamblingrunescape gambling
Back
Top