Home  >  Article  >  Backend Development  >  PHP generates verification code example code_PHP tutorial

PHP generates verification code example code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:41:13976browse

The following is the code to generate the verification code. The result was tested by Programming Home and there are no errors. If there is anything you don’t understand, you can reply and Programming Home will explain what you don’t understand. Hope it can be of benefit to you.

  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 <= 3; $i ) {
  10. imageline($imgs, rand(0, 0), rand(0, 25 ), rand(70, 100), rand(0, 25), $thr);
  11. }
  12. for ($i = 1; $i <= 200; $i ) {
  13. imagesetpixel($imgs,rand() 0,rand()5,$two);
  14. }
  15. Header("Content-type:image/jpeg ");
  16. imagejpeg($imgs);
  17. ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486153.htmlTechArticleThe following is the code to generate the verification code. The result was tested by Programming Home and there are no errors. If there is anything you don’t understand, you can reply and Programming Home will explain what you don’t understand. ...
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