almightyegg Posted September 21, 2007 Share Posted September 21, 2007 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??? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 21, 2007 Share Posted September 21, 2007 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... Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 21, 2007 Share Posted September 21, 2007 P.S. link table ref to a session... Quote Link to comment Share on other sites More sharing options...
almightyegg Posted September 21, 2007 Author Share Posted September 21, 2007 right I got it sorted . Thanks. How would I make it more complicated (eg. include letters and numbers and squirm the text a bit)???? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 21, 2007 Share Posted September 21, 2007 I've not got round to trying this yet but... http://www.phpfreaks.com/forums/index.php/topic,147174.0.html Quote Link to comment Share on other sites More sharing options...
almightyegg Posted September 21, 2007 Author Share Posted September 21, 2007 The example seemed to pull all sorts of errors How would I include the alphabet characters in my rand too? Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 21, 2007 Share Posted September 21, 2007 Can't see why any are throwing errors? At top of last two scripts is a var(s) for your text, for the first you pass it with a GET (can set though!) Quote Link to comment Share on other sites More sharing options...
almightyegg Posted September 21, 2007 Author Share Posted September 21, 2007 Unexpected T_STRINGS and such....too much hassle. I'll just go with letter and numbers if I can work mout hpow to do it.... Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted September 21, 2007 Share Posted September 21, 2007 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() Quote Link to comment Share on other sites More sharing options...
almightyegg Posted September 21, 2007 Author Share Posted September 21, 2007 Thanks that worked a treat Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.