Two PHP code _php tutorial for generating a graphics verification code

Source: Internet
Author: User
Verification code in PHP is often used, the following we provide you with some of the PHP verification code generation class and program, directly copied down can be directly used, oh, see the code below.

Verification code in the PHP tutorial is often used, below we provide you with some about PHP code generation class and program, directly copied down can be directly used, oh, see the code below.

Session_Start ();
Header ("Content-type:image/gif");
Class Securitycode
{
Private $codes = ';
function __construct ()
{
$code = ' 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-u-v-w-x-y-z ';
$codeArray = Explode ('-', $code);
Shuffle ($codeArray);
$this->codes = Implode (", Array_slice ($codeArray, 0,4));
}
Public Function createimg ()
{
$_session[' check_pic ' = $this->codes;
$img = Imagecreate (70,25);
Imagecolorallocate ($img, 222,222,222);
$testcolor 1 = imagecolorallocate ($img, 255,0,0);
$testcolor 2 = imagecolorallocate ($img, 51,51,51);
$testcolor 3 = imagecolorallocate ($img, 0,0,255);
$testcolor 4 = imagecolorallocate ($img, 255,0,255);
for ($i = 0; $i < 4; $i + +)
{
Imagestring ($img, Rand (5,6), 8 + $i * 15,rand (2,8), $this->codes[$i],rand (1,4));
}
Imagegif ($IMG);
}
}
$code = new Securitycode ();
$code->createimg ();
$code = NULL;
?>

Code two

session_start ();
for ($i =0; $i <4; $i + +) {
$rand. = Dechex (rand (1,15));
}
$_session[check_pic]= $rand;
Echo $_session[check_pic];
Set Picture size > Picture size
$im = Imagecreatetruecolor (100,30);
Set color
$BG =imagecolorallocate ($im, 0,0,0);
$te =imagecolorallocate ($im, 255,255,255);
Write the string in the upper left corner of the image
Imagestring ($im, Rand (5,6), Rand (25,30), 5, $rand, $te);
Output image
Header ("Content-type:image/jpeg");
Imagejpeg ($im);
?>

http://www.bkjia.com/PHPjc/632979.html www.bkjia.com true http://www.bkjia.com/PHPjc/632979.html techarticle Verification Code in PHP is often used, the following we provide you with some of the PHP verification code generation class and program, directly copied down can be directly used, oh, see the code below. Verify ...

  • 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.