Verification code presumably everyone has seen it, in this article for you to introduce how to implement the color of PHP code, interested friends can refer to the following
The code is as follows: <?php header ("content-type:image/png,charset= ' Utf-8 '"); $im = Imagecreatetruecolor (400, 30); //white $white = imagecolorallocate ($im, 255, 255, 255); //red $red = Imagecolorallocate ($im, 255, 0, 0; //Black $black =imagecolorallocate ($im, 0, 0, 0); //green $green =imagecolorallocate ($im, 0, 255, 0) ; //Blue $blue =imagecolorallocate ($im, 0, 0, 255); $color _arr=array ($green, $blue, $red); $color = Array_rand ($color _arr); $text = ' I'm so sick of this verification code '; $textlen =iconv_strlen ($text, ' utf-8 '); Compute string length // Randomly intercept two characters, color display $p 1=rand (1, $textlen) -1; while (($p 2=rand (1, $textlen)-1) = = $p 1); $w 1=iconv_substr ($ Text, $p 1,1, ' utf-8 '); $w 2=iconv_substr ($text, $p 1,1, ' utf-8 '); //font file (ps:t good PHP Q-buckle 峮: 276167802, Validation: CSL) $font = ' Simkai.ttf '; imagefilledrectangle ($im, 0, 0, 399, $white); for ($i =0; $i < $textlen; $i + +) { if ($i = = $p 1| | $i = = $p 2) { Imagettftext ($im,0, 20* ($i-1) +20, $color _arr[$color], $font, Iconv_substr ($text, $i, 1, ' utf-8 ')); } else Imagettftext ($im, 0, 20* ($i-1) +20, $black, $font, Iconv_substr ($text, $i, 1, ' utf-8 ')); } Imagepng ($im); Imagedestroy ($im); ?> Verify that the characters in the code are not the same color, allowing the user to enter a CAPTCHA for the specified color, which is better for security.