Script Anti-span
CaptchaSecurityImages.php
<?php session_start(); class CaptchaSecurityImages { var $font = 'monofont.ttf'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ $possible = '234567890bcdfghjkmnpqrstvwxyz'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function CaptchaSecurityImages($width='120',$height='40',$characters='6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Não é possível inicializar fluxo nova imagem GD'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Erro na função imagettfbbox'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Erro na função imagettftext'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $width = isset($_GET['width']) ? $_GET['width'] : '120'; $height = isset($_GET['height']) ? $_GET['height'] : '40'; $characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6'; $captcha = new CaptchaSecurityImages($width,$height,$characters); ?>
Formulario:
<?php session_start(); if( isset($_POST['submit'])) { if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. echo 'Thank you. Your message said "'.$_POST['message'].'"'; unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here echo 'Sorry, you have provided an invalid security code'; } } else { ?> <form action="form.php" method="post"> <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br /> <input type="submit" name="submit" value="Submit" /> </form> <?php } ?>
Esta parte de cima o codigo do anti-spam
Agora o condigo do meu fomulario que estou querendo fazer a junção.
<form action="?pg=comentarios" method=post enctype="multipart/form-data" name=formMaker onsubmit="return validar(this)"> <input name="acao" type="hidden" value="add_comentario"> <input name="id" type="hidden" value="<? echo $id?>"> <table border="0" align="center" cellpadding="2" cellspacing="0"> <tr valign=middle> <td align=right style="border-bottom:1px solid #cccccc;border-top:1px solid #cccccc;">Nome:</td> <td width="300" style="border-bottom:1px solid #cccccc;border-top:1px solid #cccccc;"> <input name="nome" type="text" size="45"></td> </tr> <tr valign=middle> <td align=right style="border-bottom:1px solid #cccccc">Comentário</td> <td style="border-bottom:1px solid #cccccc"><textarea name="comentarios" cols="44" rows="5" id="comentarios"></textarea></td> </tr> <tr valign=middle> <td align=right style="border-bottom:1px solid #cccccc">Código de Segurança:</td> <td style="border-bottom:1px solid #cccccc"><img src="estrutura/captcha/CaptchaSecurityImages.php?width=100&height=40&characters=5" /> <input id="security_code" name="security_code" type="text" /></td> </tr> <tr align="center" valign=middle> <td colspan="2"><input type=submit name=Submit value="Cadastrar"> <input type=reset name=Submit2 value="Limpar"></td> </tr> </table> </form>
//Aqui seria onde eu coloca o codigo para fazer a verificação da img não estou conseguindo fazer isto.
Alguém poderia me ajudar qual melhor forma de fazer isto.
<? } if($acao == "add_comentario"){ $sql = "INSERT INTO noticias_comentarios VALUES ('', '$id', '$nome', '$cidade', '$data', '$comentarios')"; $sql = mysql_query($sql); //echo $sql; echo " <br> <br> <center><h4>Comentário enviado com Sucesso!</h4></center> <meta http-equiv='refresh' content='2;URL=?pg=ler_noticia&id=$id'> "; } ?>