PHP Generate Verification Code picture Program _php Tutorial

Source: Internet
Author: User
A foreign web site to download the PHP generated verification code image codes, this is more practical, we also illustrate that the need for friends to save as PHP can be used oh.
code as follows copy code

"!--? 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 a error message here
Echo ' Sorry, and you had provided an invalid SECU rity code ';
}
} else {
?

!--? php
}
;

Validation Program captchasecurityimages.php

The code is as follows Copy Code

Session_Start ();

/*
* File:CaptchaSecurityImages.php
* Author:simon Jarvis
* copyright:2006 Simon Jarvis
* date:03/08/06
* updated:07/02/07
* requirements:php 4/5 with GD and FreeType libraries
* link:http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program was 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 was distributed in the hope that it'll 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-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 has 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 = ' + ', $height = ' + ', $characters = ' 6 ') {
$code = $this->generatecode ($characters);
/* Font size would 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);

?>

http://www.bkjia.com/PHPjc/629694.html www.bkjia.com true http://www.bkjia.com/PHPjc/629694.html techarticle a foreign web site to download the PHP generated verification code image codes, this is more practical, we also illustrate that the need for friends to save as PHP can be used oh. The code is copied as follows ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.