php实现简单的图片验证码

WBOY
풀어 주다: 2016-07-25 08:46:15
원래의
1069명이 탐색했습니다.

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

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


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!