public function getImgVerify(){ ob_end_clean(); $im = imagecreatetruecolor( 150 ,50 ); $white = imagecolorallocate( $im , 255 , 255 ,255); $grey = imagecolorallocate($im ,0 , 0,0); $black = imagecolorallocate($im , rand(1,255) , rand(1,255) , rand(1,255)); imagefill($im,0,0,$grey); $rand = rand( 1 , 4); $one = rand( 1 ,9); $two = rand(1 ,9); if( $rand == 1){ $result = $one + $two; $text = $one . "+" . $two . "=?"; }else if( $rand == 2){ if($one < $two){ list( $two , $one) = [ $one ,$two]; } $result = $one - $two; $text = $one . "-" . $two . "=?"; }else if( $rand == 3){ $result = $one * $two; $text = $one . "*" . $two . "=?"; }else if($rand == 4){ $res = $one * $two ; $result = $res / $one ; $text = $res . "/" . $one . "=?"; } session_start(); $_SESSION['vcode'] = $result; $font = './ArvoRegular.ttf'; $i = 0; $len = strlen( $text ); while( $i < $len ) { if (is_numeric($text[$i])) { imagettftext($im, 20, rand(-45, 45), 20 * ($i + 1), 30, $black, $font, $text[$i]); } else { imagettftext($im, 20, 0, 20 * ($i + 1), 30, $black, $font, $text[$i]); } //echo $text[$i]; $i++; } header("Content-type: image/png"); #var_dump(imagepng($im));exit; imagepng($im); imagedestroy($im); }