Home >php教程 >php手册 >php生成验证码实例代码

php生成验证码实例代码

WBOY
WBOYOriginal
2016-06-13 10:39:431297browse

下面是生成验证码代码,结果编程之家本站测试过,没错误贴上来的。如果有什么不懂的地方可以回复,编程之家会为你解释不了解之处。希望能对你有所收获。

  1. session_start();
  2. $nums       = rand(1000,9999);
  3. $_SESSION[nums]=$nums;
  4. $imgs = ImageCreatetruecolor(100, 35);
  5. $one = Imagecolorallocate($imgs, 0, 0, 0);
  6. $two = Imagecolorallocate($imgs, rand(0, 255), rand(0, 255), rand(0, 255));
  7. $thr = Imagecolorallocate($imgs, rand(50, 200), rand(100, 255), rand(150, 255));
  8. Imagestring($imgs, 6, rand(5, 60), rand(3, 18), $nums, $two);
  9. for ($i = 1; $i
  10.     imageline($imgs, rand(0, 0), rand(0, 25), rand(70, 100), rand(0, 25), $thr);
  11. }
  12. for ($i = 1; $i
  13.     imagesetpixel($imgs,rand()0,rand()5,$two);
  14. }
  15. Header("Content-type:image/jpeg");
  16. imagejpeg($imgs);
  17. ?>

Statement:
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