Jump to content

Image verification


Amy1980

Recommended Posts

Ok. Here You are:


form.php
[code]

<form method="post" name="guestform">

 
Name * 
    <input name="txtName" type="text" id="txtName" size="30" maxlength="30">

 
Email
   
    <input name="txtEmail" type="text" id="txtEmail" size="30" maxlength="50">

 
Website URL
   
    <input name="txtUrl" type="text" id="txtUrl" value="http://" size="30" maxlength="50">

 
Message * 
    <textarea name="mtxMessage" cols="80" rows="5" id="mtxMessage"></textarea>
<img src="http://michael-schenker.com/modules/guestbook/library/CaptchaSecurityImages.php?character=5" style="height:30px; width:150px;"/><br />
Security Code: <input id="security_code" name="security_code" type="text" /><br />
<input type="submit" name="submit"  onClick="return checkForm();"/>
<?php
  session_start();
  if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
      echo 'OK';// Insert you code for processing the form here
  } else {
    echo 'BAD'; // Insert your code for showing an error message here
  }

?>[/code]

Captcha.php
[code]<?php
session_start();

/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/

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',$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('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);
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code);
/* output captcha image to browser */
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'] : '6';

header('Content-Type: image/jpeg');
$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>[/code]



Link to comment
https://forums.phpfreaks.com/topic/32277-image-verification/#findComment-149940
Share on other sites

right off, your session_start() needs to go first. before <!DOCTYPE, before <html> at the very top of the document.

Also, you haven't included the code that actually inserts information into your guest book. That's the magic part that needs to go here: "insert your code for processing the form here."

hope that makes sense.
Link to comment
https://forums.phpfreaks.com/topic/32277-image-verification/#findComment-149947
Share on other sites

[quote author=michaellunsford link=topic=120378.msg493779#msg493779 date=1167509260]
right off, your session_start() needs to go first. before <!DOCTYPE, before <html> at the very top of the document.

Also, you haven't included the code that actually inserts information into your guest book. That's the magic part that needs to go here: "insert your code for processing the form here."

hope that makes sense.
[/quote]

What exacly needs to be included here?
Link to comment
https://forums.phpfreaks.com/topic/32277-image-verification/#findComment-149958
Share on other sites

hmm.. I think everything is ok, but I get error:
[code]Error, query failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Windows; U; Windows NT 5.1; pl; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1, cur' at line 1[/code]
Link to comment
https://forums.phpfreaks.com/topic/32277-image-verification/#findComment-150063
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.