Results 1 to 3 of 3

Thread: Random picture every time it's accessed

  1. #1

    Thread Starter
    Member Skootles's Avatar
    Join Date
    Jul 2005
    Posts
    34

    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.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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]);
    ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Member Skootles's Avatar
    Join Date
    Jul 2005
    Posts
    34

    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
  •  



Click Here to Expand Forum to Full Width