Captcha Sum
Zoals je al kunt lezen is dit een captcha som, dus geen foto met onleesbare tekst maar een gemakkelijke som die normaal iedereen wel zou moeten kunnen oplossen. Ik wil het ook! Als je dit voorbeeld ook wilt gebruiken maar niet echt goed weet hoe je het moet installeren, kan je mij altijd hier of het forum contacteren. Updates 1. Foto's toegevoegd 2. Gaat nu tot twintig 3. Verkorte code (snelheid) 4. Je kunt nu ook antwoorden zoals bv. fourteen, twenty-one 5. E_NOTICE waarschuwingen opgelost 6. OnClick functie toegevoegd zodat je de standaard value in het invulboxje niet altijd moet verwijderen! Komende updates 1. Nederlandse vertaling 2. Wat jullie willen Voorbeeld: http://faso.comlu.com/captcha.php Tevens is daar het voorbeeld te downloaden!
[code]
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- TITLE OF THE SITE -->
<title> Faso.comulu.com | Captcha sum </title>
<!-- MAKE THE SITE BEAUTIFULL -->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Aldrich">
<?php
/****************************************
# Make two random number to count *
# (+ or -). And change in some cases *
# the number into letters to make it *
# for spammers harder to crack (almost *
# impossible because spambots can't *
# read) *
****************************************/
/****************************************
# Set an error, so we can display them *
****************************************/
$error = '';
/****************************************
# Make a random captcha image, call the *
# images like this: captcha1, captcha2 *
****************************************/
$image = 'images/captcha'.rand(1,8).'.jpg';
/****************************************
# Create two random numbers to decide *
# if we make a plus or min exercise *
****************************************/
$plusmin = rand(1,2);
/****************************************
# Make some random numbers, number1 is *
# between 10 and twenty and the second *
# one between 1 and 9 because PHP can't *
# count 0 or -0 *
****************************************/
$number1 = rand(10,20);
$number2 = rand(1,9);
/****************************************
# Make the numbers change into letters *
# (three,seven,nine,twelve,fifteen, *
# seventeen,nineteen aren't changing) *
****************************************/
$replace = array('1' => 'one', '2' => 'two', '4' => 'four', '5' => 'five', '6' => 'six', '8' => 'eight', '10' => 'ten', '11' => 'eleven', '13' => 'thirteen', '14' => 'fourteen', '16' => 'sixteen', '18' => 'eighteen', '20' => 'twenty');
/****************************************
# Check if the random number is in the *
# array and replace it with the letters *
# variation *
****************************************/
if(array_key_exists($number1, $replace)) {
$display1 = $replace[$number1]; }
else {
$display1 = $number1; }
/****************************************
# Do the same as above, but now with *
# number two *
****************************************/
if(array_key_exists($number2, $replace)) {
$display2 = $replace[$number2]; }
else {
$display2 = $number2; }
/****************************************
# Now go back to the plus or min case *
# and display the good one, if it is 1, *
# the sum is + else it is - *
****************************************/
if($plusmin == 1) {
$display = $display1.' + '.$display2;
$sumcheck = $number1 + $number2; }
else {
$display = $display1.' - '.$display2;
$sumcheck = $number1 - $number2; }
/****************************************
# If the submitter wants that we check *
# the captcha sum. *
****************************************/
if(isset($_POST['check_sum'])) {
/****************************************
# Trim the answer and set it as *
# variable $answer *
****************************************/
$answer = trim($_POST['sum_answer']);
/****************************************
# Rewrite the sum if the answer isn't *
# numeric (only try it) *
****************************************/
if(!is_numeric($answer)) {
/****************************************
# Change it now *
****************************************/
$replace = array('one' => '1', 'two' => '2', 'three' => '3', 'four' => '4', 'five' => '5', 'six' => '6', 'seven' => '7', 'eight' => '8', 'nine' => '9', 'ten' => '10', 'eleven' => '11', 'twelve' => '12', 'thirteen' => '13', 'fourteen' => '14', 'fifteen' => '15', 'sixteen' => '16', 'seventeen' => '17', 'eighteen' => '18', 'nineteen' => '19', 'twenty' => '20', 'twenty-one' => '21', 'twenty-two' => '22', 'twenty-three' => '23', 'twenty-four', '24', 'twenty-five' => '25', 'twenty-six' => '26', 'twenty-seven' => '27', 'twenty-eight' => '28', 'twenty-nine' => '29');
/****************************************
# If the answer is in the array above, *
# change it into numbers *
****************************************/
if(array_key_exists($answer, $replace)) {
$answer = $replace[$answer]; } }
/****************************************
# Now we tried to change the number and *
# everything like that, so we can check *
# the inserted answer *
****************************************/
if($_SESSION['sum'] == $answer) {
$error = '<div class="error">Your answer is correct!</div>'; }
else {
$error = '<div class="error">Your answer isn\'t correct!</div>'; } }
/****************************************
# Unset the session at the end of the *
# code and set a new one *
****************************************/
unset($_SESSION['sum']);
$_SESSION['sum'] = $sumcheck;
?>
</head>
<body>
<div class="wrapper">
Captcha Sum
</div>
<div class="container">
<!-- ERROR -->
<?php echo $bError; ?>
<!-- CAPTCHA IMAGE -->
<div class="captcha_background">
<img src="<?php echo $aImage; ?>" />
</div>
<!-- THE SUM -->
<div class="captcha_sum">
<?php echo $aDisplay; ?>
</div>
<!-- START THE FORM -->
<form action="" method="POST">
<!-- THE ANSWER BOX -->
<div class="answer_sum">
<input type="text" name="sum_answer" value="Insert answer" onBlur="if(this.value.length == 0) this.value='Insert answer';" onClick="if(this.value == 'Insert answer') this.value='';" />
</div>
<!-- ANSWER BUTTON -->
<div class="anwer_button">
<input type="submit" name="check_sum" value="Check my sum!" />
</div>
<!-- CLOSE THE FORM -->
</form>
</div>
</body>
</html>
[/code]
[code]
/***** BODY, WRAPPER, CONTAINER *****/
body {
font-family: "Trebuchet MS", Tahoma;
font-size: 13.25px;
color: #666666;
background-color: #222931; }
.wrapper {
font-family: Aldrich;
font-size: 24px;
margin: 0 auto;
padding:0;
width: 960px;
height: 0 auto;
color: #FFFFFF; }
.container {
margin: 0 auto;
margin-top: 5px;
padding:10px;
width: 940px;
height: 0 auto;
background-color: #FFFFFF;
border-top: 2px solid #45799e;
border-bottom: 2px solid #45799e; }
/***** ERROR *****/
.error {
font-weight: bold;
margin: 0 0 5px 0;
padding: 5px;
color: #666666;
background-color: #fff799;
border: 2px solid #45799e; }
/***** CAPTCHA IMAGE *****/
.captcha_background {
margin: 0;
padding: 0; }
.captcha_background img {
width: 190px;
height: 30px; }
/***** CAPTCHA SUM *****/
.captcha_sum {
font-family: Aldrich;
font-size: 16.5px;
text-align: center;
margin: -24px 0 0 10px;
padding: 0;
width: 180px;
height: 0 auto;
color: #1d1d1d; }
/***** CAPTCHA SUM INBOX *****/
.answer_sum {
margin: -25px 0 0 195px;
padding: 0; }
.answer_sum input { padding: 4px; border: 1px solid #cccccc; }
/***** CAPTCHA ANSWER BUTTON *****/
.anwer_button {
margin: -26px 0 0 290px;
padding: 0; }
.anwer_button input { padding: 3px; border: 1px solid #cccccc; }
/***** DOWNLOAD LINK *****/
.download { margin: -22px 0 5px 780px; }
.download a:link, .download a:visited { font-family: Aldrich; text-decoration: none; color: #222931; }
.download a:hover { text-decoration: underline; }
[/code]
Reacties
0