php生成随机验证码
效果图
* Created by PhpStorm.
* User: lenovo
* Date: 2016/8/1
* Time: 11:58
*/
header("Content-Type: image/png");
for ($i=0;$i<4;$i++) {
$nmsg .= dechex(mt_rand(0,15));
echo $nmsg;
}
$im = imagecreatetruecolor(75,25);
$blue = imagecolorallocate($im,0,102,255);
$white = imagecolorallocate($im,255,255,255);
imagefill($im,0,0,$blue);
imagestring($im,5,20,4,$nmsg,$white);
ob_clean();
imagepng($im);
imagedestroy($im);
这里需要注意下 ob_clean();如果我不加这一句的话 在火狐中 显示..因其本身有错无法显示”的问题,作者也提示了说“如果浏览器显示“图像XXX因其本身有错无法显示”,在google浏览器直接显示个空的。