Implementation of PHP Verification code ____php

Source: Internet
Author: User

Internship is to do a message, the message needs to verify the code.

PHP Verification code implementation, in fact, is the first random number, and then the drawing.

The key code is in validcode.php:

<?php 
	
	Header ("Content-type:image/png");
	
	Open session
	session_start ();
	
	Random 4 digits
	$code = "";
	$arr = Array ();
	For ($i =0 $i <4; $i + +) {
		
		$arr [$i] = rand (0,9);
		$code. = (String) $arr [$i];
	}
	
	Set into session, convenient than to
	$_session["validcode"] = $code;
	
	Start drawing
	$width = m;
	$height =;
	$img = Imagecreatetruecolor ($width, $height);
	
	Fill background color
	$backcolor = imagecolorallocate ($img, 0,0,0);
	Imagefill ($img, 0,0, $backcolor);
	
	Gets a randomly darker color for 
	($i =0 $i <4; $i + +) {
		
		$textcolor = imagecolorallocate ($img, Rand (50,180), Rand (50,180), Rand (50,180)); 
		Imagechar ($img, 12,7+ $i *25,3, (String) $arr [$i], $textcolor);
	
	Display Picture
	imagepng ($img);
	
	Destroy picture
	Imagedestroy ($img);
? >

Then use a page, place the IMG tag, and introduce the verification code. Then use a label for the user to switch the verification code to prevent the situation from being seen.

 


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.