thanks for reply sneakyimp,
this captcha does work im just not sure how i can integrate with my registration form.
if you use this two scripts below they will work, but i would like to insert captcha in my form. (hich is 3rd script)
INDEX.PHP
<?php
session_start();
if( isset( $POST['secure'] ) )
{
if($POST['secure'] != $_SESSION['security_number'])
{
$error = "OOOK! Here's what you must do: click Start -> Run and write calc.";
}
else
{
$error = "Man, you're good! Your result is correct.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP math captcha</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script language="javascript" type="text/javascript">
/ this is just a simple reload; you can safely remove it; remember to remove it from the image too /
function reloadCaptcha()
{
document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
}
</script>
</head>
<body>
<div id="container">
<h1>PHP Math captcha image</h1>
<strong>Demo</strong>
<form method="post" action="">
<input type="text" name="secure" value="what's the result?" onclick="this.value=''" />
<input type="submit" value="am I right?" /><br />
<span class="explain">click on the image to reload it</span>
<img src="image.php" alt="Click to reload image" title="Click to reload image" id="captcha" onclick="javascript:reloadCaptcha()" />
</form>
<?=$error?>
</div>
</body>
</html>
IMAGE.PHP
<?php
session_start();
/*===============================================================
General captcha settings
===============================================================*/
// captcha width
$captcha_w = 150;
// captcha height
$captcha_h = 50;
// minimum font size; each operation element changes size
$min_font_size = 12;
// maximum font size
$max_font_size = 18;
// rotation angle
$angle = 20;
// background grid size
$bg_size = 13;
// path to font - needed to display the operation elements
$font_path = 'fonts/courbd.ttf';
// array of possible operators
$operators=array('+','-','*');
// first number random value; keep it lower than $second_num
$first_num = rand(1,5);
// second number random value
$second_num = rand(6,11);
/*===============================================================
From here on you may leave the code intact unless you want
or need to make it specific changes.
===============================================================*/
shuffle($operators);
$expression = $second_num.$operators[0].$first_num;
/*
operation result is stored in $session_var
*/
eval("\$session_var=".$second_num.$operators[0].$first_num.";");
/*
save the operation result in session to make verifications
*/
$_SESSION['security_number'] = $session_var;
/*
start the captcha image
*/
$img = imagecreate( $captcha_w, $captcha_h );
/*
Some colors. Text is $black, background is $white, grid is $grey
*/
$black = imagecolorallocate($img,0,0,0);
$white = imagecolorallocate($img,255,255,255);
$grey = imagecolorallocate($img,215,215,215);
/*
make the background white
*/
imagefill( $img, 0, 0, $white );
/* the background grid lines - vertical lines */
for ($t = $bg_size; $t<$captcha_w; $t+=$bg_size){
imageline($img, $t, 0, $t, $captcha_h, $grey);
}
/* background grid - horizontal lines */
for ($t = $bg_size; $t<$captcha_h; $t+=$bg_size){
imageline($img, 0, $t, $captcha_w, $t, $grey);
}
/*
this determinates the available space for each operation element
it's used to position each element on the image so that they don't overlap
*/
$item_space = $captcha_w/3;
/* first number */
imagettftext(
$img,
rand(
$min_font_size,
$max_font_size
),
rand( -$angle , $angle ),
rand( 10, $item_space-20 ),
rand( 25, $captcha_h-25 ),
$black,
$font_path,
$second_num);
/* operator */
imagettftext(
$img,
rand(
$min_font_size,
$max_font_size
),
rand( -$angle, $angle ),
rand( $item_space, 2*$item_space-20 ),
rand( 25, $captcha_h-25 ),
$black,
$font_path,
$operators[0]);
/* second number */
imagettftext(
$img,
rand(
$min_font_size,
$max_font_size
),
rand( -$angle, $angle ),
rand( 2*$item_space, 3*$item_space-20),
rand( 25, $captcha_h-25 ),
$black,
$font_path,
$first_num);
/* image is .jpg */
header("Content-type:image/jpeg");
/* name is secure.jpg */
header("Content-Disposition:inline ; filename=secure.jpg");
/* output image */
imagejpeg($img);
?>
my registration form REGISTER.PHP
<?php
if(isset($POST['Submit'])){
//NEED TO CHECK IF FIELDS ARE FILLED IN
if( empty($POST['name']) && (empty($POST['email']))){
header("Location:Messages.php?msg=3");
exit();
}
if( empty($POST['pw1']) && (empty($POST['pw2']))){
header( "Location:Messages.php?msg=4" );
exit();
}
$name=$POST['name'];
$email=$_POST['email'];
$pw1=$POST['pw1'];
$pw2=$POST['pw2'];
if("$pw1" !== "$pw2" ){
header( "Location:Messages.php?msg=5" );
exit();
}
$ip = $_SERVER['REMOTE_ADDR'];
//connect to the db server , check if uname exist
include('config.php');
$query1=("Select from user where email='$email'");
$result1= mysql_query($query1);
$num1=mysql_num_rows($result1);
if ($num1 > 0) {//Email already been used
header( "Location:Messages.php?msg=11" );
exit();
}else{
$query=("Select from user where uname='$name'");
$result= mysql_query($query);
$num=mysql_num_rows($result);
if ($num > 0) {//Username already exist
header( "Location:Messages.php?msg=6" );
exit();
}else{
//if username does not exist insert user details
$query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name','$pw1','$email',NOW(),'$ip','Normal')");
if (@ ($query)) {
header("location:login.php?reg=1");
exit;
}
}
}
mysql_close();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Registration</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="styleLog.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="7" cellpadding="0">
<tr class="temptitle">
<td><!-- InstanceBeginEditable name="EditRegion4" -->New User Registration <!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><!-- InstanceBeginEditable name="EditRegion3" -->
<form name="form1" action="register.php" method="post">
<table width="657" border="0">
<tr>
<td width="122"><div align="left">Name</div></td>
<td width="525"><input name="name" type="text" size="40"></td>
</tr>
<tr>
<td><div align="left">Email</div></td>
<td><input name="email" type="text" size="40"></td>
</tr>
<tr>
<td><div align="left">Password</div></td>
<td><input name="pw1" type="password" size="40"></td>
</tr>
<tr>
<td ><div align="left">Confirm Password </div></td>
<td><input name="pw2" type="password" size="40"></td>
</tr>
<tr>
<td></td>
<td> <input name="Submit" type="submit" value="Register"></td>
</tr>
</table>
</form>
<!-- InstanceEndEditable --></td>
</tr>
<tr>