PHP programming every day must learn the verification code, PHP programming Verification Code _php tutorial

Source: Internet
Author: User

PHP programming every day must learn the verification code, PHP programming verification code


This article for you to share the PHP picture Verification Code Implementation code, share to everyone for reference, the specific content as follows

1. Verification Code Image generation
captcha.php

1. Generate 100*30 size picture, default to Black $image = Imagecreatetruecolor (100,30);//Create white Basemap $bgcolor = Imagecolorallocate ($image, 255,255,255);//Fill black imagefill with white ($image, 0,0, $bgcolor)//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 (5,10); $y = rand (5,10); Imagestring ($image, $fontsize, $x, $y, $fontcontent, $fontcolor);} $_session["Authcode"] = $captch _CODE;//3. Add interference/interference points for ($i =0; $i <100; $i + +) {$pointcolor =imagecolorallocate ($image , Rand (50,200), Rand (50,200), Rand (50,200)); Imagesetpixel ($image, Rand (1,99), Rand (1,29), $pointcolor);} Interference line for ($i =0; $i <2; $i + +) {$linecolor =imagecolorallocate ($image, Rand (80,220), Rand (80,220), Rand (80,220)); Imageline ($image, Rand (1,99), Rand (1,29), Rand (1,99), Rand (1,29), $linecolor);} Header ("Content-type:image/png"); Imagepng ($image);

2. Page Implementation Verification Code function
form.php

<?phpif (Isset ($_post["Authcode"])) {session_start (); if (Strtolower ($_post["Authcode"]) ==$_session["Authcode"] {  echo "OK";} else{  echo "NO";}}? > 
 
  Document

The above is the entire content of this article, to help you easily implement PHP image verification code.

Articles you may be interested in:

    • PHP5 Image Verification Code implementation codes
    • PHP Verification Code Class code (the latest modification, fully customizable!)
    • A nice PHP verification code class (share)
    • A good example of PHP verification code class sharing
    • Thinkphp Verification Code using a concise tutorial
    • Thinkphp Verification Code does not show the solution
    • PHP Generate image Verification code, click to switch instances
    • PHP implementation of CAPTCHA verification code class instance
    • Perfect solution for thinkphp Verification code error cannot be displayed method

http://www.bkjia.com/PHPjc/1106131.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106131.html techarticle PHP Programming every day must learn the verification code, PHP programming Verification code This article for you to share the PHP image verification Code Implementation code, share to everyone for your reference, the specific content is as follows 1. captcha Image ...

  • 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.