Verification code supports numbers, letters, Chinese characters, and mixing
Width = $ width; $ this-> height = $ height; $ this-> codeNum = $ codeNum; $ this-> codeType = $ codeType; $ this-> fontSize = $ fontSize; $ this-> fontType = $ fontType; $ this-> codeStr = $ codeStr; $ this-> strNum = strlen ($ this-> codeStr)/3-1; $ this-> imageType = $ imageType; $ this-> checkCode = $ this-> getCheckCode ();} /// + response // * verification code generation character // + response // * @ return string // + response public function _ toString () {$ string = implode ('', $ this-> getCheckCode (); $ _ SESSION ["code"] = $ string; // add it to the session $ this-> getImage (); // output verification code return '';} protected function getCheckCode () {$ string = array (); switch ($ this-> codeType) {case 1: // numeric string $ string = array_rand (range (), $ this-> codeNum); break; case 2: // Large letter string $ string = array_rand (array_flip (range ('A', 'z'), $ this-> codeNum); break; case 3: // Chinese character string for ($ I = 0; $ icodeNum); $ I ++) {$ start = mt_rand (0, $ this-> strNum ); $ string [$ I] = self: msubstr ($ this-> codeStr, $ start);} break; case 4: // mixed string for ($ I = 0; $ icodeNum); $ I ++) {$ rand = mt_rand (); switch ($ rand) {case 0: $ ascii = mt_rand ); $ string [$ I] = sprintf ('% c', $ ascii); break;
2.
[Image]Mix .jpg
3.
[Image]Number .jpg
4.
[Image]Chinese .jpg
5.
[Image]2.16.jpg