Captcha aan formulier koppelen

Status
Niet open voor verdere reacties.

arienlans

Gebruiker
Lid geworden
15 aug 2008
Berichten
172
Ik heb een Captcha en dat wil ik aan mijn formulier koppelen.

Als ik de code intikt in het formulier dan wordt die niet als goed gezien.

Ik zie iets over het hooft maar ik weet niet wat.

wie kan mij helpen???


Formulier
PHP:
<?php  ?> 
<!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>
  <title>Contact formulier</title> 
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>Contact Formulier</h1>
<br/><hr/>
<p>Invoervelden met een <img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="15" height="15" border="0" /> zijn verplichte invoervelden.<br />
   Typ onderaan van het formulier de "Verificatiecode" over in het lege invoerveld daarnaast om te laten zien dat u geen Spam Robot bent.</p>
<form method="post" class="formulier" enctype="multipart/form-data" action="antwoord.php">
<?php
if(isset($errors) && count($errors)) {
	foreach($errors as $value) {
?>
<div class="formuliererror"><?
		print "$value<br />";
	}
?></div><?
}
?>

<p>
<label for="voornaam">Voornaam :</label>
<input type="text" id="voornaam" name="voornaam" value="<?=$_REQUEST["voornaam"]?>" />
<img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="10" height="10" border="0" /></p>

<p>
<label for="achternaam">Achternaam :</label>
<input type="text" id="achternaam" name="achternaam" value="<?=$_REQUEST["achternaam"]?>" />
<img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="10" height="10" border="0" /></p>

<p>
<label for="adres">Adres :</label>
<input type="text" id="adres" name="adres" value="<?=$_REQUEST["adres"]?>" /> Optie</p>

<p>
<label for="postcode">Postcode :</label>
<input type="text" id="postcode" name="postcode" value="<?=$_REQUEST["postcode"]?>" /> Optie</p>

<p>
<label for="woonplaats">Woonplaats :</label>
<input type="text" id="woonplaats" name="woonplaats" value="<?=$_REQUEST["woonplaats"]?>" /> Optie</p>

<p>
<label for="telefoon">Telefoon :</label>
<input type="text" id="telefoon" name="telefoon" value="<?=$_REQUEST["telefoon"]?>" /> Optie</p>

<p>
<label for="email">E-mail :</label>
<input type="text" id="email" name="email" value="<?=$_REQUEST["email"]?>" />
<img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="10" height="10" border="0" /></p>

<p>
<label for="url">URL :</label>
<input type="text" id="url" name="url" value="<?=empty($_REQUEST["url"]) ? 'http://' : $_REQUEST["url"]?>" /> Optie</p>

<p>
<label for="onderwerp">Onderwerp :</label>
<input type="text" id="onderwerp" name="onderwerp" value="<?=$_REQUEST["onderwerp"]?>" />
<img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="10" height="10" border="0" /></p>

<p>
<label for="bericht">Uw bericht : <img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="10" height="10" border="0" /></label>
<textarea id="bericht" name="bericht" rows="5" cols="25"><?=$_REQUEST["bericht"]?></textarea></p>

<p>
<label for="captcha" id="captcha">Verificatie Code :</label>
<img class="captcha" src="captcha.php" alt="Captcha" /></p>

<p>
<label for="securityCode">Typ hier de Code :</label>
<input type="text" tabindex="3" name="securityCode" id="securityCode" value="" size="8" maxlength="8"/>
<img src="gif/icon_star-1.gif" alt="Met een Ster is een verplicht invoerveld!" width="10" height="10" border="0" /></p>

<p>
<label for="contact_email_copy">Kopie van dit bericht :</label>
<input type="checkbox" name="email_copy" id="contact_email_copy" value="1"  /> E-mail een kopie naar uw eigen e-mailadres</p>

<div style="margin-left: 150px;">
<input type="submit" value="Verstuur" class="formulierbutton"/> 
<input type="reset" value="Wissen" class="formulierbutton"/>
</div>
</form>
</div>
</html>

Captcha
PHP:
<?php 
session_start(); 
$width = 140; 
$height = 35; 
$im = imagecreate($width, $height); 
$bg = imagecolorallocate($im, 0, 0, 0); 
 
// generate random string 
$len = 5; 
$chars = 'ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvw23456789'; 
 
$string = array();
 
for ( $i = 0; $i < $len; $i++ ) { 
    $pos = rand ( 0, strlen ( $chars ) - 1 ); 
    $string[$i] = $chars{$pos}; 
}
 
$string2 = implode ( '', $string );
 
$_SESSION["securityCode"] = md5($string2);
 
// grid groen
$grid_color = imagecolorallocate($im, 0, 175, 0); 
$number_to_loop = ceil($width / 20); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $x = ($i + 1) * 20; 
    imageline($im, $x, 0, $x, $height, $grid_color); 
} 
$number_to_loop = ceil($height / 10); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $y = ($i + 1) * 10; 
    imageline($im, 0, $y, $width, $y, $grid_color); 
} 
 
// grit rood
$extra_color = imagecolorallocate($im, 175, 0, 0); 
$number_to_loop = ceil($width / 15); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $x = ($i + 1) * 15; 
    imageline($im, $x, 0, $x, $height, $extra_color); 
} 
$number_to_loop = ceil($height / 20); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $y = ($i + 1) * 20; 
    imageline($im, 0, $y, $width, $y, $extra_color); 
} 
// grit blouw
$extra2_color = imagecolorallocate($im, 0, 0, 255); 
$number_to_loop = ceil($width / 25); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $x = ($i + 1) * 25; 
    imageline($im, $x, 0, $x, $height, $extra2_color); 
} 
$number_to_loop = ceil($height / 15); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $y = ($i + 1) * 15; 
    imageline($im, 0, $y, $width, $y, $extra2_color); 
} 
 
// random lines groen
$line_color = imagecolorallocate($im, 0, 130, 0); 
for($i = 0; $i < 10; $i++) { 
    $rand_x_1 = rand(0, $width - 1); 
    $rand_x_2 = rand(0, $width - 1); 
    $rand_y_1 = rand(0, $height - 1); 
    $rand_y_2 = rand(0, $height - 1); 
    imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line_color); 
} 
 
// random lines rood
$line2_color = imagecolorallocate($im, 130, 0, 0); 
for($i = 0; $i < 10; $i++) { 
    $rand_x_1 = rand(0, $width - 1); 
    $rand_x_2 = rand(0, $width - 1); 
    $rand_y_1 = rand(0, $height - 1); 
    $rand_y_2 = rand(0, $height - 1); 
    imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line2_color); 
}
 
// random lines blouw
$line3_color = imagecolorallocate($im, 0, 0, 130); 
for($i = 0; $i < 10; $i++) { 
    $rand_x_1 = rand(0, $width - 1); 
    $rand_x_2 = rand(0, $width - 1); 
    $rand_y_1 = rand(0, $height - 1); 
    $rand_y_2 = rand(0, $height - 1); 
    imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line3_color); 
}
 
// write the text 
$i=0;
while($i < $len){
$kleur1 = rand(150, 255);
$kleur2 = rand(150, 255);
$kleur3 = rand(150, 255);
$text_color = imagecolorallocate($im, $kleur1, $kleur2, $kleur3);
$rand_x = rand($width/6*$i+15, $width/6*$i+15); 
$rand_y = rand(0, $height - 15); 
imagestring($im, 10, $rand_x, $rand_y, $string[$i], $text_color); 
$i++;
}
 
 
 
header ("content-type: image/png"); 
imagepng($im); 
?>

Ariën
 
Ik mis het stuk waar het formulier afgehandeld wordt?
 
sorry was ik vergeten bij te voegen

PHP:
<?php 
session_start(); 
$width = 140; 
$height = 35; 
$im = imagecreate($width, $height); 
$bg = imagecolorallocate($im, 0, 0, 0); 
 
// generate random string 
$len = 5; 
$chars = 'ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvw23456789'; 
 
$string = array();
 
for ( $i = 0; $i < $len; $i++ ) { 
    $pos = rand ( 0, strlen ( $chars ) - 1 ); 
    $string[$i] = $chars{$pos}; 
}
 
$string2 = implode ( '', $string );
 
$_SESSION["securityCode"] = md5($string2);
 
// grid groen
$grid_color = imagecolorallocate($im, 0, 175, 0); 
$number_to_loop = ceil($width / 20); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $x = ($i + 1) * 20; 
    imageline($im, $x, 0, $x, $height, $grid_color); 
} 
$number_to_loop = ceil($height / 10); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $y = ($i + 1) * 10; 
    imageline($im, 0, $y, $width, $y, $grid_color); 
} 
 
// grit rood
$extra_color = imagecolorallocate($im, 175, 0, 0); 
$number_to_loop = ceil($width / 15); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $x = ($i + 1) * 15; 
    imageline($im, $x, 0, $x, $height, $extra_color); 
} 
$number_to_loop = ceil($height / 20); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $y = ($i + 1) * 20; 
    imageline($im, 0, $y, $width, $y, $extra_color); 
} 
// grit blouw
$extra2_color = imagecolorallocate($im, 0, 0, 255); 
$number_to_loop = ceil($width / 25); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $x = ($i + 1) * 25; 
    imageline($im, $x, 0, $x, $height, $extra2_color); 
} 
$number_to_loop = ceil($height / 15); 
for($i = 0; $i < $number_to_loop; $i++) { 
    $y = ($i + 1) * 15; 
    imageline($im, 0, $y, $width, $y, $extra2_color); 
} 
 
// random lines groen
$line_color = imagecolorallocate($im, 0, 130, 0); 
for($i = 0; $i < 10; $i++) { 
    $rand_x_1 = rand(0, $width - 1); 
    $rand_x_2 = rand(0, $width - 1); 
    $rand_y_1 = rand(0, $height - 1); 
    $rand_y_2 = rand(0, $height - 1); 
    imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line_color); 
} 
 
// random lines rood
$line2_color = imagecolorallocate($im, 130, 0, 0); 
for($i = 0; $i < 10; $i++) { 
    $rand_x_1 = rand(0, $width - 1); 
    $rand_x_2 = rand(0, $width - 1); 
    $rand_y_1 = rand(0, $height - 1); 
    $rand_y_2 = rand(0, $height - 1); 
    imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line2_color); 
}
 
// random lines blouw
$line3_color = imagecolorallocate($im, 0, 0, 130); 
for($i = 0; $i < 10; $i++) { 
    $rand_x_1 = rand(0, $width - 1); 
    $rand_x_2 = rand(0, $width - 1); 
    $rand_y_1 = rand(0, $height - 1); 
    $rand_y_2 = rand(0, $height - 1); 
    imageline($im, $rand_x_1, $rand_y_1, $rand_x_2, $rand_y_2, $line3_color); 
}
 
// write the text 
$i=0;
while($i < $len){
$kleur1 = rand(150, 255);
$kleur2 = rand(150, 255);
$kleur3 = rand(150, 255);
$text_color = imagecolorallocate($im, $kleur1, $kleur2, $kleur3);
$rand_x = rand($width/6*$i+15, $width/6*$i+15); 
$rand_y = rand(0, $height - 15); 
imagestring($im, 10, $rand_x, $rand_y, $string[$i], $text_color); 
$i++;
}
 
 
 
header ("content-type: image/png"); 
imagepng($im); 
?>

Ariën
 
Dat is weer de code van de captcha...
 
niet echt slim van mij maar hier is het bestand wat ik antwoord heb genoemd
PHP:
<?php
	session_start();

	$my_email = "mijn@email.nl";
    $subject = "<< Email via de Website van uw domein>>";

	$hasError = false;

	if (!$hasError && empty($_REQUEST["email"])) {
		$errors[] = "Voer een geldig E-mail adres in";
		$hasError = true;
	}
	if (!$hasError && !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_REQUEST["email"])) {
		$errors[] = "Je email adres is geen geldig email adres";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["voornaam"])) {
		$errors[] = "Uw 'Voornaam' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["achternaam"])) {
		$errors[] = "Uw 'Achternaam' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["onderwerp"])) {
		$errors[] = "'Onderwerp' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["bericht"])) {
		$errors[] = "'Bericht' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError) {
		if ($_SESSION["securityCode"] == $_REQUEST["securityCode"] && !empty ($_SESSION["securityCode"])) {
			unset ($_SESSION["securityCode"]);
		} else {
			$errors[] = "Typ de 'Verificatie Code' over";
			$hasError = true;
		}
	}

	if (!$hasError) {
		$message = "voornaam: " . $_REQUEST["voornaam"];
		$message .= "\nachternaam: " . $_REQUEST["achternaam"];
		$message .= "\nadres: " . $_REQUEST["adres"];
		$message .= "\npostcode: " . $_REQUEST["postcode"];
		$message .= "\nwoonplaats: " . $_REQUEST["woonplaats"];
		$message .= "\ntelefoon: " . $_REQUEST["telefoon"];
		$message .= "\nemail: " . $_REQUEST["email"];
		$message .= "\nurl: " . $_REQUEST["url"];
		$message .= "\nonderwerp: " . $_REQUEST["onderwerp"];
		$message .= "\nbericht:\n" . $_REQUEST["bericht"];

		$from_name = $_REQUEST['voornaam'] . ' ' . $_REQUEST['achternaam'];
		$headers = "From: {$from_name} <{$_REQUEST['email']}>";
		mail($my_email, $subject, $message, $headers);
		if ($_REQUEST["email_copy"] == "1") {
			mail($_REQUEST["email"], $subject, $message, $headers);
		}
		include("bedankt.php");
	} else {
		include("contact_formulier.php");
	}
?>

Ariën
 
Ik zie dat je in de captcha.php een md5 over de code heen gooit, maar volgensmij doe je dat in de controle niet... daar zou het best eens mee te maken kunnen hebben.
 
Er zit nog ergens een foutje
Parse error: syntax error, unexpected ',', expecting ']' in /home/sites/228/http/test/form/antwoord.php on line 34
deze foutmelding krijg ik
dit heb ik gemaakt
PHP:
<?php
	
	$my_email = "mijn@email.nl";
    $subject = "<< Email via de Website van uw domein>>";

	$hasError = false;

	if (!$hasError && empty($_REQUEST["email"])) {
		$errors[] = "Voer een geldig E-mail adres in";
		$hasError = true;
	}
	if (!$hasError && !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_REQUEST["email"])) {
		$errors[] = "Je email adres is geen geldig email adres";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["voornaam"])) {
		$errors[] = "Uw 'Voornaam' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["achternaam"])) {
		$errors[] = "Uw 'Achternaam' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["onderwerp"])) {
		$errors[] = "'Onderwerp' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["bericht"])) {
		$errors[] = "'Bericht' is een verplicht veld";
		$hasError = true;
	}
	if (!$hasError && empty($_REQUEST["secrityCode", md5($code) != $_REQUEST["secrityCode"])){
		$errors[] = "Typ de 'Verificatie Code' over";
		$hasError = true;
		}
	}

	if (!$hasError) {
		$message = "voornaam: " . $_REQUEST["voornaam"];
		$message .= "\nachternaam: " . $_REQUEST["achternaam"];
		$message .= "\nadres: " . $_REQUEST["adres"];
		$message .= "\npostcode: " . $_REQUEST["postcode"];
		$message .= "\nwoonplaats: " . $_REQUEST["woonplaats"];
		$message .= "\ntelefoon: " . $_REQUEST["telefoon"];
		$message .= "\nemail: " . $_REQUEST["email"];
		$message .= "\nurl: " . $_REQUEST["url"];
		$message .= "\nonderwerp: " . $_REQUEST["onderwerp"];
		$message .= "\nbericht:\n" . $_REQUEST["bericht"];

		$from_name = $_REQUEST['voornaam'] . ' ' . $_REQUEST['achternaam'];
		$headers = "From: {$from_name} <{$_REQUEST['email']}>";
		mail($my_email, $subject, $message, $headers);
		if ($_REQUEST["email_copy"] == "1") {
			mail($_REQUEST["email"], $subject, $message, $headers);
		}
		include("bedankt.php");
	} else {
		include("contact_formulier.php");
	}
?>
 
PHP:
  if (!$hasError && empty($_REQUEST["secrityCode", md5($code) != $_REQUEST["secrityCode"])){

Er ontbreekt een ] in deze regel :) Je kunt de juiste locatie vast wel vinden ;)
 
in mijn captcha heb ik dit
PHP:
$_SESSION["Code"] = md5($string2);

in antwoord het ik dit staan
PHP:
if (!$hasError && empty($_REQUEST["secrityCode"]), md5($_SESSION["Code"] != $_REQUEST["secrityCode"]) {
			unset ($_SESSION["securityCode"]);
		} else {
			$errors[] = "Typ de 'Verificatie Code' over";
			$hasError = true;
		}
	}

ergens gaat het nog niet lekker wat ik ook doe het lukt mij niet

Ariën
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan