Jump to content

[SOLVED] another image verification help post


almightyegg

Recommended Posts

My problem is that I need to get the $rand from the image, but I don't know how.

 

<?

$rand = rand(10000, 99999); // I want to get this and use a hidden input to send to the next page on my form so I can see whether the user got it right....

$image = imagecreate(60, 30);

$bgColor = imagecolorallocate ($image, 255, 255, 255); 

$textColor = imagecolorallocate ($image, 0, 0, 0); 

imagestring ($image, 5, 5, 8, $rand, $textColor); 

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"); 
header('Content-type: image/jpeg');

imagejpeg($image);

?>

 

So on my form I want to get the $rand...can I do this???

Link to comment
Share on other sites

The way I did it was to gen a code and then hash it with a seed. I then saved both in mysql. Then when I gen'd the page, the link to the image gen had the hash sent along with GET. The image gen code then did a query to find out what the code was and then generated the image. This way the code is not on the calling page for bot's to find...

Link to comment
Share on other sites

I pulled this out of one of the user comments in the online PHP Manual

 

<?php

// this is to generate a random selection from an array with array_rand preety nice, can be used to generate random passwords or anything:

$my_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "0", "1", "2", "3", "4", "5");
       for ($i=0; $i<=10; $i++)
       {
           $random = array_rand($my_array);
                       //this generates the random number from the array
           $parola .= $my_array[$random];
                       //here we will display the exact charachter from the array
       }
       echo $parola; // printing result 

?>

 

The key function here is array_rand()

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.