html code:
<html>
<head>
<title> New Document </title>
<script src="jquery-1.5.1.min.js"> </script>
<script type="text/javascript">
function reloadcode()
{
var timestamp = Date.parse(new Date());
$("#img").attr('src','check.php/'+timestamp); //这里换成你的地址
}
</script>
</head>
<body>
<form method="post" action ="">
<img src="check.php" id ="img" >     
<input type ="button" title="点击刷新" value ="看不清换一张" οnclick="reloadcode()" ><br>
<input type ="submit" value ="提交">
</form>
</body>
</html>
check.php code:
<?php
//1.生成随即数
//2.session存起来
//3.创建图片
//4.将数字写进图片
//echo rand(1,20);
//echo dechex(rand(1,15));
session_start();
header("Cache-Control: no-cache, must-revalidate");
for($i=1;$i<=4;$i++)
{
$num=$num.dechex(rand(1,15));
}
//创建一个60*20的图形
$img=imagecreate(50,25);
//设置颜色
$bg=imagecolorallocate($img,255, 255, 255);
$textColor=imagecolorallocate($img,0,0,0);//
$color = imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
//向图片写入文字
imagestring($img,5,7,5,$num,$textColor);
imagerectangle($img , 0 , 0 ,49 , 24 , $textColor);
$_SESSION['checkCode']=$num;
header('Content-Type:image/jpeg');
imagejpeg($img);
?>