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???

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...

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()

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.