The daily required verification code for php programming, and the php programming Verification Code

Source: Internet
Author: User

The daily required verification code for php programming, and the php programming Verification Code

This article shares the php image verification code for your reference. The details are as follows:

1. Verification Code Image Generation
Captcha. php

// 1. generate an image of 100*30. The default value is black $ image = imagecreatetruecolor (255,255,255, 30); // create a white basemap $ bgcolor = imagecolorallocate ($ image ); // fill in the black imagefill ($ image, $ bgcolor) with white; // 2. random display of numbers or letters $ captch_code = ""; for ($ I = 0; $ I <4; $ I ++) {$ fontsize = 6; $ fontcolor = imagecolorallocate ($ image, rand (0,120), rand (0,120), rand (0,120); $ data = "abcdefghijkmnpqrstuvwxy3456789"; $ fontcontent = substr ($ data, rand (0, strlen ($ data), 1); $ captch_code. = $ fontcontent; $ x = ($ I * 100/4) + rand (); $ y = rand (); imagestring ($ image, $ fontsize, $ x, $ y, $ fontcontent, $ fontcolor);} $ _ SESSION ["authcode"] = $ captch_code; // 3. add disturbance // disturbance point for ($ I = 0; $ I <100; $ I ++) {$ pointcolor = imagecolorallocate ($ image, rand (50,200 ), rand (50,200), rand (50,200); imagesetpixel ($ image, rand (), rand (), $ pointcolor );} // interference line for ($ I = 0; $ I <2; $ I ++) {$ linecolor = imagecolorallocate ($ image, rand (80,220), rand (80,220 ), rand (80,220); imageline ($ image, rand (), rand (), $ linecolor );} header ("content-type: image/png"); imagepng ($ image );

2. Implement the verification code function on the page
Form. php

<? Phpif (isset ($ _ POST ["authcode"]) {session_start (); if (strtolower ($ _ POST ["authcode"]) ==$ _ SESSION ["authcode"]) {echo "OK" ;}else {echo "NO" ;}}?> <! Doctype html> 

The above is all the content of this article, helping you easily implement the php image verification code.

Articles you may be interested in:
  • Php5 image Verification Code
  • PHP Verification Code (latest modification, fully customized! )
  • A beautiful php Verification Code Class (SHARE)
  • Share a handy PHP Verification Code instance
  • Simple ThinkPHP Verification Code tutorial
  • Thinkphp Verification Code cannot be displayed
  • PHP generates image verification codes and click to switch instances
  • Captcha Verification Code instance implemented by php
  • Perfect solution to the problem that thinkphp Verification Code fails to be displayed

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.