php生成图形验证码
2018-07-20 来源:open-open
<?php
session_start();
// main
$vcodes = '';
//generate Number 4
srand((double) microtime() * 1000000);
for ($i = 0; $i < 4; $i++) {
$vcodes .= rand(1, 9);
}
$_SESSION['eifr_checkvcode'] = $vcodes;
if (function_exists('imagecreate')) {
//generate picture validation code
Header("Content-type: image/PNG");
$img = imagecreate(44, 18);
$bg = ImageColorAllocate($img, 245, 245, 245);
imagefill($img, 0, 0, $bg); //background
//generate Number 4
for ($i = 0; $i < 4; $i++) {
$font = ImageColorAllocate($img, rand(100, 255), rand(0, 100), rand(100, 255));
$vnum = substr($vcodes, $i, 1);
imagestring($img, 5, 2 + $i * 10, 1, $vnum, $font);
}
//add interference
for ($i = 0; $i < 100; $i++) {
$randcolor = ImageColorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($img, rand() % 70, rand() % 30, $randcolor);
}
ImagePNG($img);
ImageDestroy($img);
}
?>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:Asp.Net 加密解密
最新资讯
热门推荐