首页 >后端开发 >php教程 >php实现简单的图片验证码

php实现简单的图片验证码

WBOY
WBOY原创
2016-07-25 08:46:151125浏览

这是最简单的图片验证码:

image.php

  1. header("Content-type: image/png");
  2. $string = "abcdefghijklmnopqrstuvwxyz0123456789";
  3. for($i=0;$i $pos = rand(0,36);
  4. $str .= $string{$pos};
  5. }
  6. $img_handle = ImageCreate (60, 20) or die ("Cannot Create image");
  7. //Image size (x,y)
  8. $back_color = ImageColorAllocate($img_handle, 255, 255, 255);
  9. //Background color RBG
  10. $txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
  11. //Text Color RBG
  12. ImageString($img_handle, 31, 5, 0, $str, $txt_color);
  13. Imagepng($img_handle);
  14. session_start();
  15. $_SESSION['img_number'] = $str;
  16. ?>
复制代码

form.php
  1. php实现简单的图片验证码
  2. 更多 0
  3. php
  4. 验证码
  5. 这是最简单的图片验证码:
  6. image.php
  7. header("Content-type: image/png");
  8. $string = "abcdefghijklmnopqrstuvwxyz0123456789";
  9. for($i=0;$i $pos = rand(0,36);
  10. $str .= $string{$pos};
  11. }
  12. $img_handle = ImageCreate (60, 20) or die ("Cannot Create image");
  13. //Image size (x,y)
  14. $back_color = ImageColorAllocate($img_handle, 255, 255, 255);
  15. //Background color RBG
  16. $txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
  17. //Text Color RBG
  18. ImageString($img_handle, 31, 5, 0, $str, $txt_color);
  19. Imagepng($img_handle);
  20. session_start();
  21. $_SESSION['img_number'] = $str;
  22. ?>
  23. form.php
  24. Random Number

复制代码

result.php

  1. session_start();
  2. if($_SESSION['img_number'] != $_POST['num']){
  3. echo'The number you entered doesn't match the image.
  4. Try Again
    ';
  5. }else{
  6. echo'The numbers Match!
  7. Try Again
    ';
  8. }
  9. ?>
复制代码


验证码, php


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn