阅读背景:

为什么session中的验证码 比图片中慢半拍

来源:互联网 
code.php代码

<?php
session_start();
function create_code(){
for($i=0;$i<4;$i++){
$_code.=dechex(mt_rand(0,15));
}
$_SESSION['code']=$_code;
$_width=75;
$_height=25;
$_img=imagecreatetruecolor($_width, $_height);
header('Content-Type:image/png');
$_color_white=imagecolorallocate($_img, 255, 255, 255);
$_color_black=imagecolorallocate($_img, 0, 0, 0);
//填充白色
imagefill($_img, 0,0,$_color_white);
//画一个边框
imagerectangle($_img,0,0,$_width-1,$_height-1,$_color_black);
//画一些线条
for($i=0;$i<4;$i++){
$_color_rand=imagecolorallocate($_img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
imageline($_img, mt_rand(0,$_width), mt_rand(0,$_height), mt_rand(0,$_width), mt_rand(0,$_height), $_color_rand);
}
for($i=0;$i<20;$i++){
$_color_rand=imagecolorallocate($_img, mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));
imagestring($_img, 1,mt_rand(0,$_width-3),mt_rand(0,$_height-3), "*", $_color_rand);
}
imagestring($_img, 5,20,5, $_SESSION['code'], $_color_black);
imagepng($_img);
imagedestroy($_img);
}
create_code();
?>

测试代码
test.php

<?php
session_start();
?>
<img src='code.php'/>

<?php echo $_SESSION['code']?>code.php代码

<?php
session_start();
function cre



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: