Author Topic: PHP Math Captcha  (Read 134 times)

0 Members and 1 Guest are viewing this topic.

Offline pedja

  • Supporter
  • **
  • Posts: 9
  • Karma: +3/-0
PHP Math Captcha
« on: July 17, 2010, 09:05:53 AM »
index.php
Code: [Select]
<form method="POST" action="cc.php">
<img src="captchas.php"> <br>
<input type="text" size="10" name="check"> <br>
<input type="submit" name="submit" value="submit">
</form>

captchas.php
Code: [Select]
<?php session_start(); 
$img imagecreatefrompng('black.png'); 
//value 1
$numeroa rand(19);
//value2
$numerob rand(19);
$numero $numeroa $numerob;
$display $numeroa '+' $numerob;
$_SESSION['check'] = $numero
//The function imagecolorallocate creates a 
//color using RGB (red,green,blue) format.
$white imagecolorallocate($img255255255); 
imagestring($img1083$display$white);
 
header ("Content-type: image/png"); imagepng($img); 
?>


cc.php
Code: [Select]
<?php
session_start
(); 
//Sessions in PHP are started by using the 
//session_start() function.  
//Like the setcookie( ) function, 
//the session_start function must come before any HTML, 
//including blank lines, on the page.session_start(); 
//Check if the security code and 
//the session value are not blank 
//and if the input text matches the stored text
if(($_POST['check']) == $_SESSION['check']) { 
echo 
'Input OK';
}else{ 
echo 
'Input Wrong';        
}

black.png