Basic Turing / Captcha

Been playing around with this most of the day


<?php function randomkeys($length) { $pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789"; for($i=0;$i<$length;$i++) { $key .= $pattern{rand(0,60)}; } return $key; } $code = randomkeys(5); header("Content-type: image/png"); $im = imagecreatetruecolor(50, 20); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, 70, 25, $white); $font = imageloadfont("comicbd.ttf"); imagestring($im, $font+5, 4, 4, "$code", $black); imagepng($im); ?>


I know how to put the file into the page

<img src="whatever.php">

What i dont understand is how to validate it against a text field in another page.

easyest is to use sessions:

$code = randomkeys(5);

then the html:

<img src="whatever.php" /><br /> <input type="text" name="code" value="" />

on the next page:
[php]if($_POST[‘code’]!=$_SESSION[‘code’]) …[/php]

Right i got it now.

Where can I find more out about sessions because they seem to be used a lot, also not very familiar with cookies. Do you know of any good info sites

no i never used any other site than

of cause there is a lot about sessions, as well:

Sponsor our Newsletter | Privacy Policy | Terms of Service