//第一段代码生成随机图片------code2.php - //开启session以用于保存生成的内容
- session_start();
- $table=array(
- "pic0"=>"dog",
- "pic1"=>"cat",
- "pic2"=>"fish",
- "pic3"=>"bird"
- );
- $index=rand(0,3);
- $value=$table['pic'.$index];
- $_SESSION['authcode']=$value;
- //得到随机生成的图片名
- $filename=dirname(__FILE__).'/pic'.$index.'.jpg';
- $content=file_get_contents($filename);
- header('Content-type:image/jpg');
- echo $content;
- ?>
//第二段代码实线表单的验证 - if(isset($_REQUEST['authcode'])){
- session_start();
- if($_REQUEST['authcode']==$_SESSION['authcode']){
- echo "right";
- }else{
- echo "sad story
"; - echo $_REQUEST['authcode'];
- }
- }
- ?>
- ?>
/*代码的路径是linux的路径*/
|