700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > php图形验证码接口 php生成图形验证码

php图形验证码接口 php生成图形验证码

时间:2023-07-29 17:17:29

相关推荐

php图形验证码接口 php生成图形验证码

[php]代码库<?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);

}

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。