Het enige waar ik nu mee zit, is dat ik de melding blijf krijgen dat de ingetoetste code fout is.
Ik zit hier inmiddels een paar uur op te zoeken en staren, maar ik zie niet waar de fout zit.
Wie kan/wil mij helpen??
Dit is mijn captcha.php
<?php
session_start();
$width = 150; // breedte
$height = 30; // hoogte
$len = 4; // lengte tekst
$fontsize = 50; // lettergrootte
unset($random_text);
$lchar = 0;
$char = 0;
/**************************************************
$random_text is de code
**************************************************/
// tekst maken
for($i = 0; $i < $len; $i++) {
while($char == $lchar) {
$char = rand(48, 109);
if($char > 57) $char += 7;
if($char > 90) $char += 6;
}
$random_text .= chr($char);
$lchar = $char;
}
$fontwidth = ImageFontWidth($fontsize) * strlen($random_text);
$fontheight = ImageFontHeight($fontsize);
// afbeelding grootte
$im = imagecreate($width,$height);
// achtergrond maken
$background_colour = imagecolorallocate($im, 204, 0, 0);
// tekst kleur
$text_colour = imagecolorallocate($im, rand(150,255), rand(150,255), rand(150,255));
// border
imagerectangle($im, 0, 0, $width-1, $height-1, $text_colour);
// string tekenen
imagestring($im, $fontsize, rand(3, $width-$fontwidth-3), rand(2, $height-$fontheight-3), $random_text, $text_colour);
//output
header("Content-type: image/png");
imagepng($im,'',80);
imagedestroy($im);
$_SESSION["verify"] = $random_text;
?>
En dit is mijn formulier:
<?php
session_start();
require('connection.inc.php');
#####################################
## © 2008 Wouter De Schuyter
## <[email protected]>
## Guestbook V1.0
#####################################
// SET VARIABLES
//////////////////
$minName = 2; // minimum lenght name
$maxName = 32; // maximum lenght name
$minEmail = 8; // minimum lenght email
$maxEmail = 256; // maximum lenght email
$minMessage = 8; // minimum lenght message
$maxMessage = 2560; // maximum lenght message
///////////////////
$act = $_GET['action'];
// FUNCTIONS
//////////////
// REPLACE TEXT BY EMOTICONS
function emoticons($string) {
$emoticonsDirectory = "img/emoticons"; // directory from emoticons | example: "img/emoticons"
$array1 = array(
'^^',
'(!)',
'(?)',
'(A)',
'(a)',
':)',
'=)',
'(:',
'(=',
'):',
')=',
':(',
'=(',
';)',
':d',
':D',
'=d',
'=D',
':p',
':P',
'=p',
'=P',
'(8)',
':s',
':S',
'=s',
'=S',
's:',
'S:',
's=',
'S=',
':o',
':O',
'=o',
'=O',
'o:',
'O:',
'o=',
'O=',
'(l)',
'(L)',
':$',
'=$',
'$:',
'$=',
':\'(',
'=\'(',
')\'=',
')\':',
':@',
'=@',
' >< ',
'-_-',
'-.-',
'f5'
);
$array2 = array(
'<img src="' . $emoticonsDirectory . '/happy.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/exclamationmark.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/questionmark.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/angel.png" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/angel.png" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/smile.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/smile.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/smile.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/smile.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/sad.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/sad.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/sad.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/sad.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/wink.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/biggrin.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/biggrin.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/biggrin.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/biggrin.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/tongue.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/tongue.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/tongue.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/tongue.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/bandit.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/confused.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/ooo.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/heart.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/heart.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/blush.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/blush.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/blush.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/blush.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/crying.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/crying.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/crying.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/crying.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/angry.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/angry.gif" alt="Emoticon" />',
' <img src="' . $emoticonsDirectory . '/hmmpff.gif" alt="Emoticon" /> ',
'<img src="' . $emoticonsDirectory . '/hmmpff.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/hmmpff.gif" alt="Emoticon" />',
'<img src="' . $emoticonsDirectory . '/hmmpff.gif" alt="Emoticon" />'
);
$output = str_replace($array1, $array2, $string);
return $output;
}
// UBB CODE
function ubb($string) {
$array1 = array(
'[b]',
'[/b]',
'[u]',
'[/u]',
'[center]',
'[/center]',
'[i]',
'[/i]'
);
$array2 = array(
'<b>',
'</b>',
'<u>',
'</u>',
'<center>',
'</center>',
'<i>',
'</i>'
);
$output = str_replace($array1, $array2, $string);
return $output;
}
// VALID
function valid($string) {
$array1 = array(
'<br>',
'<noscript>'
);
$array2 = array(
'<br />',
'*noscript*'
);
$output = str_replace($array1, $array2, $string);
return $output;
}
echo '
<a href="?action=homepage">Beginpagina</a>
|
<a href="?action=addComment">Teken gastenboek</a>
|
<a href="?action=viewComments">Bekijk gastenboek</a>';
// WHEN ACTION IS "Add Comment"
if($act == "addComment") {
echo "<h3>Teken gastenboek</h3>\n";
if($_SERVER['REQUEST_METHOD'] == "POST") {
$name = addslashes(ucfirst(trim($_POST['name']))); // NAME
$email = addslashes($_POST['email']); // EMAIL
$showEmail = $_POST['showEmail']; // SHOW/HIDE EMAIL
$emoticons = $_POST['emoticons']; // ENABLE/DISABLE EMOTICONS
$message = addslashes(ucfirst(trim($_POST['message']))); // MESSAGE
$captcha = $_POST['captcha']; // CAPTCHA
$captchaVer = $_SESSION['captcha']; // CAPTCHA CHECK
$time = date("Y/m/d H:i:s"); // TIME
$ip = $_SERVER['REMOTE_ADDR']; // IP
$regexp = "/^[a-z0-9_]+([_\\.-][a-z0-9_]+)*@([a-z0-9_]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i"; // EMAIL CHECK
// GENERAL FIELD CHECK
if(strlen($name) < 1 or strlen($email) < 1 or strlen($message) < 1 or strlen($captcha) < 1) {
echo "<p>Vul alle verplichte velden in!</p>\n";
$generalError = true;
}
elseif($generalError !== true) {
// CHECK NAME LENGHT
if(strlen($name) < $minName) {
echo "<p>Je naam moet uit minimaal " . $minName . " bestaan! Maak je naam langer.</p>\n";
$lenghtError = true;
}
elseif(strlen($name) > $maxName) {
echo "<p>Je naam mag niet meer dan " . $maxName . " bevatten! Maak je naam korter.</p>\n";
$lenghtError = true;
}
// CHECK EMAIL LENGHT
if(strlen($email) < $minEmail) {
echo "<p>Je emailadres moet uit minimaal " . $minEmail . " bestaan! Maak je emailadres langer.</p>\n";
$lenghtError = true;
}
elseif(strlen($email) > $maxEmail) {
echo "<p>Je emailadres mag niet meer dan " . $maxEmail . " bevatten! Maak je emailadres korter.</p>\n";
$lenghtError = true;
}
// CHECK MESSAGE LENGHT
if(strlen($message) < $minMessage) {
echo "<p>Je bericht moet uit minimaal " . $minMessage . " bestaan! Maak je bericht langer.</p>\n";
$lenghtError = true;
}
elseif(strlen($message) > $maxMessage) {
echo "<p>Je bericht mag niet meer dan " . $maxMessage . " bevatten! Maak je bericht korter.</p>\n";
$lenghtError = true;
}
// CHECK CAPTCHA LENGHT
if(strlen($captcha) !== 4) {
echo "<p>Je verificatie code MOET uit 4 tekens bestaan!</p>\n";
$lenghtError = true;
}
if($lenghtError !== true) {
// VALID EMAIL ?
if(!preg_match($regexp, $email)) {
echo "<p>Je emailadres is ongeldig! Prboeer het nog een keer.</p>\n";
$error = true;
}
// CAPTCHA CORRECT?
if($captcha !== $captchaVer) {
echo "<p>Je verificatie code was fout! Probeer het nog een keer.</p>\n";
$error = true;
}
if($error !== true) {
$insertQuery = "INSERT INTO `guestbook` (`name`, `email`, `showEmail`, `enableEmoticons`, `message`, `time`, `ip`) VALUES ('" . $name . "', '" . $email . "', '" . $showEmail . "', '" . $emoticons . "', '" . $message . "', '" . $time . "', '" . $ip . "')";
$insert = mysql_query($insertQuery);
if($insert) {
echo "<p>Je bericht is met succes geplaatst!<br /><a href=\"?action=viewComments\">Klik hier</a> om het gastenboek te lezen.</p>\n";
$success = true;
}
else {
echo "<p>Fout<br />" . mysql_error() . "</p>\n";
}
}
}
}
}
if($success !== true) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php echo $act; ?>" method="post">
<table>
<tr>
<td>Naam</td>
<td><input type="text" name="name" maxlength="<?php echo $maxName; ?>" value="<?php echo stripslashes($name); ?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" maxlength="<?php echo $maxEmail; ?>" value="<?php echo stripslashes($email); ?>" /></td>
</tr>
<tr>
<td>Email zichtbaar voor anderen?</td>
<td>
Ja <input type="radio" name="showEmail" value="1"<?php if($showEmail == 1) { echo " checked=\"checked\""; } ?> />
Nee <input type="radio" name="showEmail" value="0"<?php if($showEmail == 0) { echo " checked=\"checked\""; } ?> />
</td>
</tr>
<tr>
<td>Smilie's aan?</td>
<td>
Ja <input type="radio" name="emoticons" value="1"<?php if($emoticons == 1) { echo " checked=\"checked\""; } ?> />
Nee <input type="radio" name="emoticons" value="0"<?php if($emoticons == 0) { echo " checked=\"checked\""; } ?> />
</td>
</tr>
<tr>
<td>Bericht</td>
<td><textarea name="message" rows="4" cols="30"><?php echo stripslashes($message); ?></textarea></td>
</tr>
<tr>
<td><img src="captcha/captcha.php" alt="Verificatie code" /></td>
<td><input type="text" name="captcha" maxlength="4" size="6" /> <span class="note">(Verificatie code (anti-spam))</span></td>
</tr>
<tr>
<td><input type="reset" value="Wissen" /></td>
<td><input type="submit" value="Versturen" /></td>
</tr>
</table>
</form>
<?php
}
}
// WHEN ACTION IS "View Comment(s)"
elseif($act == "viewComments") {
$sql = "SELECT `name`, `email`, `showEmail`, `enableEmoticons`, `message`, `time` FROM guestbook ORDER BY `id` DESC";
$dataQuery = mysql_query($sql);
echo "<h3>Bekijk gastenboek (" . mysql_num_rows($dataQuery) . ")</h3>\n";
if(mysql_num_rows($dataQuery) == 0) {
echo "<p>Er staan nog geen berichten in het gastenboek. <a href=\"?action=addComment\">Plaats het eerste bericht!</a></p>\n";
}
else {
while($data = mysql_fetch_assoc($dataQuery)) {
?>
<table border="1px" width="400px">
<tr>
<td><?php if($data['showEmail'] == 1) { ?><a href="mailto:<?php echo $data['email']; ?>"><?php } echo stripslashes($data['name']); if($data['showEmail'] == 1) { ?></a><?php } ?> Datum: <?php $date = new DateTime($data['time']); echo $date->format('d/m/Y, H:i:s'); ?></td>
</tr>
<tr>
<td>
<?php
$message = ubb(nl2br(stripslashes(htmlentities(valid($data['message'])))));
if($data['enableEmoticons'] == 1) {
echo emoticons($message);
}
if($data['enableEmoticons'] == 0) {
echo $message;
}
?>
</td>
</tr>
</table>
<?php
}
}
}
?>
p.s. de smilies/emoticons werken nog niet. ;-)