|
-
Jan 2nd, 2006, 11:56 PM
#1
Thread Starter
Member
Random picture every time it's accessed
Well I'm sure everyone's seen this at one time or another. It's when someone has an image displaying on a page, and every time you refresh it, a different picture appears. Now, I'm talking about the actual image changing, but the name remaining the same.
For example, you load the page, and the image shows up. The image's location is "http://www.whatever.com/image.jpg". Now, you refresh the page, and the image is different, but it's still located at "http://www.whatever.com/image.jpg".
So hopefully that makes sense... and I'm wondering how would I do this? Does anyone know of a tutorial anywhere? I tried google, but didn't find what I was looking for.
If you need more clarification, just reply and I'll try to explain as best I can.
-
Jan 3rd, 2006, 01:08 AM
#2
Re: Random picture every time it's accessed
Do you mean like the picture in my signature? Here's the script I use, it's written in PHP: 
PHP Code:
<?php
$dir = opendir('.');
$file_array = array();
while(($file = readdir($dir)) !== false) {
/* create an array of all jpeg imagesi n the current directory */
if (strtolower(substr($file, -3)) == 'jpg') {
$file_array[] = $file;
}
}
/* send headers to prevent the browser from caching the image */
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
header('Content-Type: image/jpeg');
srand((float) microtime() * 10000000);
$file = array_rand($file_array);
/* display a random picture */
readfile($file_array[$file]);
?>
-
Jan 3rd, 2006, 01:53 AM
#3
Thread Starter
Member
Re: Random picture every time it's accessed
Yep, just like that.
So would I have to put that php code into my sig? [I'm doing it for a forum too :P]
EDIT: Actually, I think I'd just have to host that and then put the link to the page as the image... I'll try it out 
EDIT 2: Yep, worked perfectly. Thanks alot
Last edited by Skootles; Jan 3rd, 2006 at 02:44 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|