Results 1 to 7 of 7

Thread: Image verification code not working firefox

  1. #1

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

    Image verification code not working firefox

    I found this tutorial, but I don't know why it does not work with firefox. It works fine with IE, can anyone help please?

    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");
    header('Cache-Control: no-cache');

    // 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);


    ?>

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

    Re: Image verification code not working firefox

    uhh, well, I don't know how you're trying to view it, but if you're just opening the PHP file in the browser, then it won't work in any browser because you're saving the image to "verify.png" on the webserver.. and uhh, you can't really save a session into an image. I think what you might be looking to do is something like this instead:

    random.php (script that displays the image)
    PHP Code:
    <img src="random.image.php" />
    <
    a href="./random.next.php">next ></a
    random.next.php (script that displays your session)
    PHP Code:
    your session:
    <blockquote>
    <pre>
    <?php
      session_start
    ();
      
    print_r($_SESSION);
    ?>
    </pre>
    </blockquote>
    random.image.php (script that makes the image -- just a small change from the script you originally posted)
    PHP Code:
    <?php
    // initialize session
    session_start();

    header("Content-Type: image/png");
    header('Cache-Control: no-cache');

    // 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);

    // destroy the image to free up the server memory
    imagedestroy($image);
    ?>
    it works fine for me.

  3. #3

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

    Re: Image verification code not working firefox

    sorry I forgot to mention that sessions is for the user's credentials, there are more codes not just this. So it has nothing to do that with image code, and also I have codes that displays the image, which I did not include. My question is, it works with IE but not firefox. *clueless*

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

    Re: Image verification code not working firefox

    but the image you're creating is just an image. images don't not work in certain browsers. that script runs fine in both firefox and internet explorer :/. it created the image both times on my web server. you're going to have to tell me HOW that script isn't working. is it not creating an image? not creating a session? not running at all? how are you calling the script? are you calling that script within an <img> tag? if so, then it won't work at all, in either browser. like I said in my post, you're saving the image instead of displaying it, so if you called that script within an <img> tag it wouldn't work. you'd have to set the <img> source to 'verify.png' instead; but even so, you have no real reason to save the image in the first place.

    is this making any sense to you?

  5. #5

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

    Re: Image verification code not working firefox

    Hm.. kows, this is what I have for my img src <img src="verify.png" width="60" height="30"> in the same file. Not sure if this answers your question.

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

    Re: Image verification code not working firefox

    and how are you calling the script you pasted above? just using one of the include functions?

  7. #7

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

    Re: Image verification code not working firefox

    no the script that i pasted above and the image src are in one page. I didn't not seperate them. Is that the cause?

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