Home » » Php chaptcha

Php chaptcha

Simple but effective php chaptcha, coded on php only, means it doesnt require javascript.
It's a simple chaptcha but it can do the job very well.


Download


chaptcha.php code:

<?php
session_start();

// http://less4us.blogspot.com

$data = array(
0 => array('Are you human?' => 'yes'),
1 => array('2 + 2 =' => '4'),
2 => array('8 - 0 =' => '8'),
3 => array('5 + 2 =' => '7'),
4 => array('4 + 2 =' => '6'),
5 => array('Barac' => 'Obama'),
6 => array('Type snake' => 'snake'),
7 => array('Type bird' => 'bird'),
8 => array('Type google' => 'google'),
9 => array('Type firefox' => 'firefox'),
10 => array('Type music' => 'music'),
);

$rand = array_rand($data);
$key = key($data[$rand]);
            $ques = $key;
            $ans = $data[$rand][$key];

// create image
header("Content-type: image/png");
    $img = imagecreatetruecolor(270,40);

    $green = imagecolorallocate($img, 0, 255, 0);
    $red = imagecolorallocate($img, 255, 0, 0);

    imagefill($img, 0, 0, $green);
    imagettftext($img, 20, 0, 5, 25, $red, "blazed.ttf", $ques);

    imagepng($img);
    imagedestroy($img);
$_SESSION['answer'] = $ans;
?>

index.php or whatever you want to call it:

<?php
session_start();


if(isset($_SESSION['answer']) && !empty($_POST['answer'])){


if($_POST['answer'] == $_SESSION['answer']){
echo ('Welcome human');
unset($_SESSION['answer']);
}
else{
die('Hi bot');
unset($_SESSION['answer']);
}


}
else{
?>
<style type="text/css">
#code, #go{
outline: none;
background: #ccc;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #6495ED;
padding: 5px;
text-decoration: none;
color: #6495ED;
}
</style>
<img src="chaptcha.php"><br>
Enter code:<br>
<form action="d.php" method="post">
<input type="text" name="answer" id="code">
<input type="submit" id="go">
</form>
<?php
}
?>

4 תגובות:

  1. excellent description!! keep up this helpful stuff
    Feel free to visit my weblog rgv homes for sale

    ReplyDelete
  2. well, random() could be used, and different font for each letter/number.
    Good Work!

    ReplyDelete
  3. yes can be used but this is just an simple implemention who does lot of work

    ReplyDelete

Follow by Email