<?php
session_start();
$table=array(
'pic0'=>'兔',
'pic1'=>'狗',
'pic2'=>'猫',
'pic3'=>'熊猫',
);
$index=rand(0,3);
$value=$table['pic'.$index];
$_SESSION['authcode']=$value;
$filename=dirname(__FILE__).'\\pic'.$index.'.jpg';
$contents=file_get_contents($filename);
header('content-type:image/jpg');
echo $contents;
?>
<?php
header("Content-type: text/html; charset=utf-8");
if(isset($_REQUEST['authcode'])){
session_start();
if($_REQUEST['authcode']==$_SESSION['authcode']){
echo '<font>验证码输入正确</font>';
}else{
echo '<font>验证码输入错误</font>';
}
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title> New Document </title>
<meta charset="utf-8"/>
</head>
<body>
<form method="post" action="./form.php">
<p>验证码图片:<img id="authcode" border="1" src="./index_image.php?r=<?php echo rand();?> width=300 height=300">
<a href="javascript:void(0)" onclick="document.getElementById('authcode').src='./index_image.php?r='+Math.random()">换一个</a>
</p>
<p>请输入图片中的内容:<input type="type" name="authcode" value=""/></p>
<p><input type="submit" value="提交" style="padding:6px 20px;"></p>
</form>
</body>
</html>