<?php
Session_Start (); Open session at the very beginning of the file
Put both English and Chinese into two arrays
$english _arr=array (' Q ', ' W ', ' e ', ' r ', ' t ', ' y ', ' u ', ' i ', ' o ', ' P ', ' a ', ' s ', ' d ', ' f ', ' g ', ' H ', ' J ',
' K ', ' l ', ' Z ', ' x ', ' C ', ' V ', ' b ', ' n ', ' m ');
$chinese _arr=array (' One ', ' two ', ' three ', ' four ', ' five ', ' VI ', ' VII ', ' VIII ', ' IX ', ' Ten ', ' 0 ', ' wood ', ' and ', ' I ',
' People ', ' there ', ' ', ' right ', ' Lord ', ' production ', ' for ', ' this ', ' work ', ' on ', ' Down ', ' left ';
/**
* Access to Chinese and English
*/
/**
* Get a random number, random letter, Random Chinese
*/
for ($i =0; $i <5; $i + +)
{
$index =rand (0,2);
if ($index = = ' 0 ')
{
$num. =rand (0,9);
echo "<font color=red> $num </font><br>";
}
else if ($index = = ' 1 ')
{
$num. = $english _arr[rand (0,25)];
echo "<font color=blue> $num </font><br>";
}
else if ($index = = ' 2 ')
{
Echo $num;
$num. = $chinese _arr[rand (0,25)]; If you are adding Chinese, you want to convert the encoding
echo "<font color=green> $num </font><br>";
}
}
$_session[check_num]= $num; Write this verification code into session.
Echo $_session[check_num];
Imagecreatetruecolor (wide, high)
$image =imagecreatetruecolor (150,50); Create a picture of a 100,30
Imagecolorallocate (image name, red, blue, green) three primary colors
Imagecolorallocate ($image, Rand (0,255), Rand (0,255), Rand (0,255));//The first time is to set the picture background color, three primary colors randomly
$color =imagecolorallocate ($image, 255,255,255);//later in order to create a color
Imagestring (image name, font type 1-6 six kinds, x coordinate, y coordinate, content, color)
Imagestring ($image, Rand (3,6), 10,3, $num, $color); Write the contents to the picture cannot output Chinese
Imagettftext (image name, font size, offset angle, x-coordinate, y-coordinate, color, font file address, input) this content must be encoded at the time of input
Imagettftext ($image, Rand (15,18), 0,rand (2,50), Rand (30,39), $color, ' Simkai.ttf ', iconv (' GBK ', ' UTF-8 ', $num)); Write the contents in the picture, can have Chinese
/**
* Draw lines and dots to do interference
*/
for ($i =0; $i <10; $i + +)
{
$linecolor =imagecolorallocate ($image, Rand (0,255), Rand (0,255), Rand (0,255));
Imageline ($image, Rand (0,150), Rand (0,50), Rand (0,150), Rand (0,50), $linecolor);
}
for ($i =0; $i <200; $i + +)
{
$pixelcolor =imagecolorallocate ($image, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($image, Rand (0,150), Rand (0,50), $pixelcolor);
}
/**
* Output Image
*/
Echo Dechex (rand (0,15));
Header ("Contenttype:image/jpeg"); Set this file to what the situation is output here is as a picture
Imagejpeg ($image); Print images in JPEG format
?>
PHP captcha code sharing