Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/06/2007, 18:48
Avatar de leskolpykos
leskolpykos
 
Fecha de Ingreso: junio-2007
Ubicación: Caracas
Mensajes: 96
Antigüedad: 16 años, 10 meses
Puntos: 0
Pregunta problema con código captcha

encontré un código captcha mucho mejor al que todos por aca han expuesto, es mas corto y la imagen de seguridad que crea es mucho más atractiva.

pero no se como aplicarlo a mi formulario, copie donde copie el codigo no me funciona, yo no se programar porque no es mi área y ya no se que hacer los hacker me tienen mi libro de visitas vuelto un nido de propagación de virus. si alguno puede ayudarme a decir en que parte de todo este cerro de letras debo pegar mi codigo del libro de visitas, gracias de antemano.

******mi formulario es este****

guest.php


//el código php

<?php

$datafile = "msgs.data";

if(isset($_POST[content])) {
extract($_POST);

$oldarray = fopen("$datafile", "r");
$oldcontents = fread($oldarray, filesize($datafile)) or die( 'Could not read from file.');
fclose($oldarray);

if(!$fp = fopen("$datafile", "w")){
die("Error: PHP does not appear to have permission to write to $datafile");
}
fwrite ($fp, "<b>Enviado por:</b> $name - ");
fwrite ($fp, date("d/n/y [h:i:s A]"));
fwrite ($fp, "<br><b>Email:</b> <font color='#FFFFFF'><a href='mailto:$email'>$email</a></font><br>");
fwrite ($fp, "<b>Título:</b> $title<br><b>Mensaje:</b><br>");
fwrite ($fp, stripslashes($content) . "<br><hr noshade size=1><br>");
fwrite ($fp, $oldcontents);
fclose($fp);
header("Location: $_SERVER[PHP_SELF]");
}
?>

//el formulario

<form method="post" action="<? echo $_SERVER[PHP_SELF]; ?>">
</font>
<span class="Estilo4">
<b><font style='font-family:Verdana' color="#FFCC00">Escribe tu mensaje aquí y
exprésate como quieras!!</font><font size=2 style='font-family:Verdana'><br>
<br>
Nombre:</font></b><font color="#FFCC00" size="2" style="font-family: Verdana">*</font><font style='font-family:Verdana; font-size:8pt'>
</font><font size=2 style='font-family:Verdana'>&nbsp;<input type="text" name="name" style="font-family: Verdana; font-size: 10pt; color: #800000; border: 1px solid #800000" size="20"><br>
</font>
</span>
<span class="Estilo4">
<font style='font-family:Verdana; font-size:2pt'><br>
</font><font size=2 style='font-family:Verdana'><b>Email:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="email" size="20" style="font-family: Verdana; font-size: 10pt; color: #800000; border: 1px solid #800000"><br>
</font><font style='font-family:Verdana; font-size:2pt'>
<br>
</font><font size=2 style='font-family:Verdana'><b>Título:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="title" style="font-family: Verdana; font-size: 10pt; color: #800000; border: 1px solid #800000" size="20">
<br>
</font><font style='font-family:Verdana; font-size:2pt'><br>
</font><font size=2 style='font-family:Verdana'><b>Mensaje:</b><font color="#FFCC00">*</font>
<textarea name=content rows=6 cols=47 wrap=soft style="font-family: Verdana; font-size: 10pt; color: #800000; border: 1px solid #800000"></textarea><br>
</font><font style='font-family:Verdana; font-size:2pt'><br></font><font style='font-family:Verdana; font-size:7pt'>[</font><font color="#FFCC00" size="2" style="font-family: Verdana">*</font><font style='font-family:Verdana; font-size:7pt'>Campos
obligatorios]&nbsp; </font><font size=2 style='font-family:Verdana'>
<input type="submit" name="submitButton" value="Publicar" style="font-family: Verdana; color: #FFFFFF; font-size: 8pt; border: 1px solid #FFFFFF; background-color: #CC0000"></form>




y este es el código del captcha, es muy bueno para quien lo sepa entender y utilizar. Algo de éste código debe ir pegado en el de mi form, y no se donde...


form.php

<?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">
<label for="name">Name: </label><input type="text" name="name" id="name" /><br />
<label for="email">Email: </label><input type="text" name="email" id="email" /><br />
<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
<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
}
?>



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 = '23456789bcdfghjkmnpqrstvwxyz';
$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',$c haracters='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('Cannot initialize new GD image stream');
/* 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('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* 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);

?>


espero alguien pueda asesorarme, gracias