Results 1 to 6 of 6

Thread: [RESOLVED] img verification code

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [RESOLVED] img verification code

    Hi guys, I have the code below in one file called img.php, but I odn't know why everytime I refresh the IE, the image code never got changed.

    PHP Code:
    <?php
    // initialize session
    session_start();
    // send header so telling the connectiont that we are about to send an image
    header("Content-Type: image/png");

    // generate 5 digits random number
    $rand rand(1000099999);

    // create the hash for the random numbers and put them in the session
    $_SESSION['img_random_value'] = md5($rand);

    // create the image
    $image imagecreate(6030);

    // set the background color to white - this has to come first
    $bgColor imagecolorallocate($image255255255);

    // set the text color to black
    $txtColor imagecolorallocate($image000);

    // write the image
    //imagefill($image, 0, 0, $bgColor);
    imagestring($image558$rand$txtColor);

    // output it to browser
    imagepng($image"verify.png");

    // destroy the image to free up the server memory
    imagedestroy($image);

    ?>
    PHP Code:
        <tr>
          <
    td width="33%">
          <
    p style="margin-left: 10"><font color="#FF0000">* </font>Verify Image
          Code 
    as shown</td>
          <
    td width="67%" valign="top"><input type="text" name="random" size="5">
          <
    img src="verify.png" width="60" height="30"></td>
        </
    tr

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: img verification code

    It is possible that it is being cached. Try refreshing by pressing Ctrl+F5 instead of F5. If that works, then it is definitely a caching issue, which you can fix by sending a Cache-Control header.
    PHP Code:
    header('Cache-Control: no-cache'); 

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: img verification code

    Yes you are right, I did that ctrl F5, and it works. But I put the code you gave, still go back and refresh/F5, not working

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: img verification code

    ah I just notice that it works with my computer at school and home but not at work, what's going on? is it cause of some settings of the IE on my computer?

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: img verification code

    are they all using the same version of IE? you could try clearing your temporary files on the work computer and see if that helps?

    you could try using this, a quick 'add-on' to what penagate suggested earlier. taken from PHP.net's header() documentation:
    PHP Code:
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
    alternatively, as a workaround you could always call your image with a recent time stamp as the query string. this way, it will force your client to grab a new copy because a time stamp is always going to be changing.
    PHP Code:
    <img src="img.php?<?php echo time(); ?>" />
    edit: and if you still have problems, you could try going a bit overboard:
    PHP Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0"false);
    header("Pragma: no-cache"); 
    Last edited by kows; Apr 24th, 2007 at 03:32 PM.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: img verification code

    ah kows, you are awesome and thanks to P too.

    I used the time stamp. Can't help it I need to force the client's computer to do that. Otherwise, who knows other user's computer might have the kind of cach feature i have on my work computer. I hope it wont cause any bad error

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