<?php/** * created by phpstorm. * user: administrator * date: 2017\10\10 0010 * time: 19:44 */ //generates a random verification code $strnumber = join (", Range (0,9)), $strChar = join (', Range (' A ', ' Z ')), $str = $strNumber. $ Strchar.strtoupper ($strChar); $str = substr (Str_shuffle ($str), ' 0 ', 4); Header ("Content-type: image /png ")//Create canvas $width = 100; $height = 50; $image = imagecreate ($width, $height);// Create Color $bgcolor = imagecolorallocate ($image, Rand (0,20), Rand (0,20), Rand (0,20));//Alternate color (interference line) $ Colorone = imagecolorallocate ($image, Rand (100,155), Rand (200,155), Rand (100,155)); /Interference line for ($j =0; $j <10; $j + +) { imageline ($image, rand (0, $width), Rand (0, $height -20), rand (0, $width), rand (0, $height), $colorone);} Loops add characters to the canvas the coordinates of each character (total width / number of verification codes) for ($i =0; $i <4; $i + +) { //alternate color (text) $fontcolor = imagecolorallocate ($ Image,rand (0,255), Rand (100,200), Rand (180,255)); $x = (($width / 4) * $i) + $width / 10; $y = rand ($height-20); imagechar ($image, 5, $x, $y, $str [$i], $fontcolor);} Imagepng ($image); Imagedestroy ($image);
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/A6/DF/wKioL1ncy2CR3-aSAABGfWyFtBc245.png-wh_500x0-wm_ 3-wmp_4-s_998014518.png "style=" Float:none; "title=" Qq20171010213942.png "alt=" Wkiol1ncy2cr3-asaabgfwyftbc245.png-wh_50 "/>
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/08/2D/wKiom1ndOm7TzOYXAABgH-WuCgM475.png-wh_500x0-wm_ 3-wmp_4-s_1187110826.png "style=" Float:none; "title=" Qq20171010213947.png "alt=" Wkiom1ndom7tzoyxaabgh-wucgm475.png-wh_50 "/>
This article is from the "ybt-php" blog, make sure to keep this source http://ybtphp.blog.51cto.com/13257319/1971297
PHP Learning Notes-Simple process-oriented verification code