PHP generates a code program with interference _php tutorial

Source: Internet
Author: User
This paper introduces a high security verification generator, which can take interference lines and other content, which can effectively prevent users from using the program to identify the difficulty of verification code.
The code is as follows Copy Code

/*
* Created on 2011-3-11
* Programmer:xiaoyao, qq:1045195056
Validation by judging the value of the input value and $_session[' Check_pic ']
*/
Session_Start ();
function Randascii ($number) {//$number produce numbers and letters
$arr =array (' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ',
' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' w ', ' V ', ' u ', ' x ', ' y ', ' z ');
for ($i =1; $i <= $number; $i + +)
{
$rand = $rand. $arr [Rand (0,35)];
}
return $rand;
}
$rand =randascii (4);

$_session[' check_pic ']= $rand;//A randomly generated four-digit assignment SESSION for validation.
$x = 80;
$y = 24;
$im =imagecreatetruecolor ($x, $y);//Create Picture
$BG =imagecolorallocate ($im, 255,255,255);//Set color background
Imagefill ($im, 0,0, $BG);
$wh =imagecolorallocate ($im, 255,255,0);
$grey =imagecolorallocate ($im, 128,128,128);
$yellow =imagecolorallocate ($im, 255,255,0);
$red =imagecolorallocate ($im, 0,255,0);
$FOREGROUNDARR = Array (imagecolorallocate ($im, rand (0,), rand (0,), rand (0, 20)),
Imagecolorallocate ($im, rand (0,), rand (0, 245, 255)),
Imagecolorallocate ($im, rand (245, 255), rand (0,), rand (0, 10)),
Imagecolorallocate ($im, rand (245, 255), rand (0,), rand (245, 255))
);//Word color array
Draw Border
$border = Imagecolorallocate ($im, 133, 153, 193);
Imagerectangle ($im, 0, 0, $x-1, $y-1, $border);

for ($i =0; $i <10; $i + +) {//Draw interference lines, 10 strips
Imageline ($im, Rand (0,60), 2,rand (0,60), $yellow);

}
for ($j =0; $j <100; $j + +) {
Imagesetpixel ($im, Rand ()%76,rand ()%20, $red);
}
Imagestring ($im, 6,15,8, $rand, $WH);//font size 1-5
Imagettftext ($im, 14,rand ( -30), 5, Rand (All), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [0]);
Imagettftext ($im, 14,rand ( -50), Rand (at), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [1];
Imagettftext ($im, 14,rand ( -50), A, rand (at), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [2];
Imagettftext ($im, 14,rand ( -30), 0,3, Rand, $FOREGROUNDARR [rand ()], ' C:windowsfontsarial.ttf ', $rand [3]);

Header ("Content-type:image/jpeg");//Output picture
Imagejpeg ($im);
Imagedestroy ($im);
?>

Calling methods

The code is as follows Copy Code
/*
* Created on 2011-3-11
* Programmer:xiaoyao, qq:1045195056
Validation by judging the value of the input value and $_session[' Check_pic ']
*/
Session_Start ();//Open session
if (Isset ($_post[' check '))
{
if ($_post[' check ')
{
if ($_post[' check ']==$_session[' Check_pic '))
{
echo "Captcha is correct". $_session[' Check_pic ';
}
Else
{
echo "Captcha error". $_session[' Check_pic ';
}
}
}
?>

http://www.bkjia.com/PHPjc/629697.html www.bkjia.com true http://www.bkjia.com/PHPjc/629697.html techarticle This paper introduces a high security verification generator, which can take interference lines and other content, which can effectively prevent users from using the program to identify the difficulty of verification code. Code to copy code as follows ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.