First on the index.php page
function identity () {$this->load->view (' index ', $data); } function codes () {if ($_post[' code '] = = $_session[' code ')} {echo ' OK '; }else{echo ' no '; }} function Create_code () {session_start (); Generate Verification Code picture Ob_clean (); Header ("Content-type:image/png"); Full Digital $STR = "1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f";//To display the characters, you can add or remove $list =explode (",", $str); $r =count ($list)-1; $laststr = ""; for ($i =0; $i <4; $i + +) {$randnum =mt_rand (0, $r); $laststr. = $list [$randnum];//Remove the characters and combine them into the string to be displayed} $_session[' code ']= $laststr; Put the string into the session//echo $laststr; $img =imagecreate (28,28);//Generate Picture $black =imagecolorallocate ($img, 0,0,0); Set color $white =imagecolorallocate ($img, 255,255,255); $gray =imagecolorallocate ($img, 200,200,200); $red =imagecolorallocate ($img, 255,0,0); $cl = IMAgefill ($img, 0,0, $red);//fill the picture with the color//put the validation method into the picture imagestring ($img, 4,10,8, $laststr, $black);//place validation on the image for ($i =0; $i <8; $i + +) {$lineColor = Imagecolorallocate ($img, Rand (0,255), Rand (0,255), Rand (0,255 )); Imageline ($img, rand (0, $x), 0,rand (0, $x), $y, $lineColor); }//Interference point for ($i =0; $i <250; $i + +) {Imagesetpixel ($img, rand (0, $x), rand (0, $y), $fontColor); } $AA = Imagepng ($img); $BB = Imagedestroy ($img); Echo $aa; }
On the View page index.php
can go and try to see