Ok, some people may have been wondering how my image in my sig changed. When you cant put a randomize script in your sig.
Well its actly quite simple as the randomiser is actly in the image.
so isnetd of banner.gif
you have banner.php
It then genirates the headers to tell the computer loading it, that it is an image, and not a php script.
the script below only works with .gif 's athogh you could cahnge this.
to ad more images, simply ad to the array, and chnage the currant image in the array to the images you want in the randomize.
hope this helps some one
PHP Code:<?php
// tells it its a gif image
Header("Content-type: image/gif");
// dates back a bit (so dosnt go in cache, so peeps actaly see chnages)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// ye be modifed always (so dosnt go in cache, so peeps actaly see chnages)
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1 - no (so dosnt go in cache, so peeps actaly see chnages)
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0 - no (so dosnt go in cache, so peeps actaly see chnages)
header("Pragma: no-cache");
//image arrays
// just ad decres it to remove images, also chnage image1.gif etc to images you wnat to dimainc image to randomize "/
$stuff = array (
0 => "image1.gif",
1 => "image2.gif",
2 => "image3.gif",
);
$display=rand(0, sizeof($stuff)-1);
//include it and done
include($stuff[$display]);
?>
Exstendered
Ok you have a dinamic image, but you want to use it on a forum. BUT the forum only supports valide image types, gif, jpg, png etc?
Well with a bit of help from .htaccss files its possible to run file types as other file types.
Heres an exsample of a finshed part
http://www.thybag.co.uk/php/speacal/myimage.png
The file type in PNG. yet refresh it, and it chnages like the php exsample
OK how do i do this. Well its axtly quite simple if your host supports .htaccess
As a htaccess effects all files below it, its best to creat a new directy for this, then put the script and the images in it.
Next choose what image typed youd like the php genirator to be, for my exsample i choose png.
creat a new file, called .htaccess
now htaccess can over ride both the apachi handlers and the MIME Types, as well as adding new ones, if you wanted a .pie files for exsample
Anyway to ad the MIME Type, use this format
The bit that says add MIME type isCode:AddType application/x-httpd-php .png
The middle is what type to addCode:AddType
Above ive used the php file typeCode:application/x-httpd-php
and the last bit is what exsention to apply it to
This can be used for ANY exstention, and aply any file type.Code:.png
Say if i was just renaime a .html document this would be all i need. But as im doing this for a php document, the apachi server needs to genrate the php on it, or there would be an error
we add a apchi handler in the same way, exspt with one diffence
[code]
AddHandler application/x-httpd-php .png
[code]
that is we use the ad handler command insted of the addtype command.
so in your .htaccess file you should have
Now save this. and then chnage the exstention on the php file with the random banner script on it, to in this exsampe .png .Code:AddType application/x-httpd-php .png AddHandler application/x-httpd-php .png
Now due to the .htaccess all .png file in this directory will be treated as php, and are therefore the script will genriate succefuly and give you the random image.
The only flaw in this is some versions of IE (helpfuly) decide to ignore the information there given, and attempt to treat the file on its own mime file type database, wich can cause errors.








Reply With Quote







