You know that simple numbers or letter verification codes can be easily cracked, but the formula verification code or Chinese Character Verification Code cannot be easily cracked. Therefore, we recommend that you try to use the formula verification code or Chinese character when using the verification code.
You know that simple numbers or letter verification codes can be easily cracked, but the formula verification code or Chinese Character Verification Code cannot be easily cracked. Therefore, we recommend that you try to use the formula verification code or Chinese character when using the verification code.
Now more and more websites are using Chinese Character verification codes, which increases the intimacy of Chinese people and the difficulty of machine cracking. Here I will give you a rough description...
Create a background canvas
$ Image = imagecreatetruecolor (200, 60); $ background = imagecolorallocate ($ image, 255,255,255); imagefill ($ image, 0, 0, $ background );
Draw interference points
For ($ I = 0; $ I <300; $ I ++) {$ pixColor = imagecolorallocate ($ image, rand (150,240), rand (150,240 ), rand (150,240); $ pixX = rand (10,190); $ pixY = rand (5, 55); imagesetpixel ($ image, $ pixX, $ pixY, $ pixColor );}
Draw interference lines
// Four horizontal lines for ($ I = 0; $ I <5; $ I ++) {$ lineColor = imagecolorallocate ($ image, rand (50,150 ), rand (50,150), rand (50,150); $ lineX1 = 0; $ lineX2 = 300; $ lineY1 = ($ I + 1) * 12; $ lineY2 = ($ I + 1) * 12; imageline ($ image, $ lineX1, $ lineY1, $ lineX2, $ lineY2, $ lineColor );} // 10 vertical lines for ($ I = 0; $ I <30; $ I ++) {$ lineColor = imagecolorallocate ($ image, rand (50,150 ), rand (50,150), rand (50,150); $ lineX1 = ($ I + 1) * 10; $ lineX2 = ($ I + 1) * 10; $ lineY1 = 0; $ lineY2 = 60; imageline ($ image, $ lineX1, $ lineY1, $ lineX2, $ lineY2, $ lineColor );}
Draw Chinese Characters
$ Text = array ('hangzhou', 'sub', 'hua', 'Kai'); for ($ I = 0; $ I <4; $ I ++) {$ textColor = imagecolorallocate ($ image, rand (20,100), rand (20,100), rand (20,100); $ textX = $ I * 50 + 10; $ textY = rand (40, 60); imagettftext ($ image, 30, rand (20, 50), $ textX, $ textY, $ textColor, "/Library/Fonts/ 文. ttf ", $ text [$ I]);}
Note that the font file must support Chinese characters.
UTF-8 is used for encoding. Do you need to convert gbk to Chinese? [iconv function can help you]
Output Image
Header ("Content-Type: image/png"); imagepng ($ image );
Destroy Resources
Imagedestroy ($ image );
After a rough look, the Chinese verification code will be displayed. Of course, when a website is used, there will be a Chinese Character Library seed, and a specific number of Chinese characters will be randomly retrieved from it for display, finally, the session is recorded for verification.
The above is all the content of this article. I hope you will like it.