PHP generates a coded program with interference

Source: Internet
Author: User
Tags php tutorial rand
The code is as follows Copy Code

<?php Tutorial
/*
* Created on 2011-3-11
* Programmer:xiaoyao, qq:1045195056
Validation by judging input values and $_session[' check_pic ' values
*/
Session_Start ();
function Randascii ($number) {//$number produces 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);

The

$_session[' check_pic ']= $rand;//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),
  Imagecolorallocate ($im, rand (0), rand (0,), rand (245, 255)),
  Imagecolorallocate ($im, rand (245, 255), rand (0,), rand (0, 1 0),
  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 line, 10
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 (a), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [0]);
Imagettftext ($im, 14,rand ( -50), Rand (a), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [1]);
Imagettftext ($im, 14,rand ( -50), EUR, Rand (a), $foregroundArr [Rand (0,3)], ' C:windowsfontsarial.ttf ', $rand [2]);
Imagettftext ($im, 14,rand ( -30), 0,3, Rand (a), $foregroundArr [Rand ()], ' C:windowsfontsarial.ttf ', $rand [3]);

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

Call method

  code is as follows copy code
<?php
/*
* Created on 2011-3-11
* Programmer:xiaoyao, qq:1045195056
Validation by judging input values and $_session[' check_pic ' values
*/
Session_Start ()//Open session
if (Isset ($_post[' check '))
{
if ($_post[' check ')]
{
if ($_post[' check ']==$_session[' Check_pic '])
{
echo "Verify code is correct". $_session[' Check_pic '];
}
Else
{
echo "Authenticode error". $_session[' Check_pic '];
}
}
}
?>
<form method=post action= "" >
<br> <!----link pictures--->
<input type= "text" name= "Check" >
<input type= "Submit" value= "submitted" >
</FORM>

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.