Random Image Snippet

By [M]ike on Jan 22, 2007

Simply place the first main php code into image.php then enter the last two code lines into a .htaccess file! Put images into the right directory, change the locations where needed and voila! The image will change every time you refresh.
This is my first PHP snippet on Hawkee so please give constructive criticism!

##Random Image PHP Snippet##
##By [M]ike - For Hawkee.com##
##Create image.php and put this into it##
<?php
header("Content-type: image/png");

$avatars[] = "images/1.png";
$avatars[] = "images/2.png";
$avatars[] = "images/3.png";
$avatars[] = "images/4.png";
$avatars[] = "images/5.png";

$avatar = $avatars[mt_rand(0, count($avatars)-1)];

$newavatar = imagecreatefrompng($avatar);
imagepng($newavatar);
imagedestroy($newavatar);
?>
##Now create a .htaccess file and put this into it##

RewriteEngine On
RewriteRule image.png image.php

##Now your done!##

Comments

Sign in to comment.
aldog   -  Nov 09, 2007

Does anything need to go above or below the htaccess code?
I\'m guessing that the point of that code is to prevent caching of files in certain browsers. But I ask because after adding it into my site I started getting an internal server error (500).

 Respond  
[M]ike   -  Jan 24, 2007

The htaccess means that you can view the link to the script through image.png so you can use it for signatures etc. since .php won\'t be a recognised image format.

 Respond  
F*U*R*B*Y*   -  Jan 24, 2007

question 1) why is there a write to .htaccess about image.png? :s

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.