Daily required verification code for php programming

Source: Internet
Author: User
This article shares the php image verification code for your reference. The details are as follows. captcha is generated for the verification code image. php1. generate an image of the size of 100*30. The default value is black $ imageimagecreatetruecolor (255,255, 30). Create a white basemap $ bgcolorimagecolorallocate ($ image, 25

This article shares the php image verification code for your reference. The details are as follows. captcha is generated for the verification code image. php // 1. generate an image of 100*30. The default value is black $ image = imagecreatetruecolor (255,255, 30); // create a white basemap $ bgcolor = imagecolorallocate ($ image, 25

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"; }}?> 
  Document

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

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.