Home > Backend Development > PHP Tutorial > PHP simple image verification code implementation

PHP simple image verification code implementation

WBOY
Release: 2016-07-25 08:42:56
Original
802 people have browsed it

//The first code generates random pictures------code2.php

  1. //Open session to save the generated content
  2. session_start();
  3. $table=array (
  4. "pic0"=>"dog",
  5. "pic1"=>"cat",
  6. "pic2"=>"fish",
  7. "pic3"=>"bird"
  8. );
  9. $index =rand(0,3);
  10. $value=$table['pic'.$index];
  11. $_SESSION['authcode']=$value;
  12. //Get the randomly generated picture name
  13. $filename=dirname( __FILE__).'/pic'.$index.'.jpg';
  14. $content=file_get_contents($filename);
  15. header('Content-type:image/jpg');
  16. echo $content;
  17. ?>
Copy code


//Verification of the second code solid line form

  1. if(isset($_REQUEST['authcode'])){
  2. session_start();
  3. if($_REQUEST['authcode' ]==$_SESSION['authcode']){
  4. echo "right";
  5. }else{
  6. echo "sad story
    ";
  7. echo $_REQUEST['authcode'];
  8. }
  9. }
  10. ? >
  11. picture:


  12. //Switch to another image through js
  13. change picture
  14. words:< ;input type="text" name="authcode" value="" />

  15. ?>
Copy code


/*The path of the code is the path of linux*/


Verification code, PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template