PHP Image Verification Code

Source: Internet
Author: User

1. Principle

Each picture in the array corresponds to a value, a random value, gets and saved to $_session,-> gets the picture of the random value,-> __file__ output picture,-> browser validation

2. Code

captcha.php

<?PHPSession_Start();//Picture Correspondence$picArray=Array(    ' pic00 ' = ' dog ', ' pic01 ' = ' cat ', ' pic02 ' and ' fish ', ' pic03 ' and ' bird ');//Random Value$index=Mt_rand(0,3);$value=$picArray[' Pic0 '.$index];$_session[' authcode '] =$value;$filename=dirname(__file__).‘. /img/pic0 '.$index.‘. jpg;//echo $filename;$content=file_get_contents($filename);Header(' Content-type:image/jpg ');Echo $content;

form.php

<?PHPif(isset($_request[' Authcode '])) {    Session_Start(); //Judging    if(Strtolower($_request[' authcode '] = =Strtolower($_session[' Authcode ']))) {        Echo' Congratulations on your typing right! ‘; } Else {        Echo' Input failed! ‘; }    Exit();}?> for= "Authcode" > Please enter the contents of the Picture: </label> <input type= "text" name= "Authcode" id= "Authcode"/> </p> <p><input type= "Submit" value= "Submit"/></p></form></body>

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.