我想做一个图片验证码,并且输入图片中的文字到表单中,其中我写了一个类
class ImageDisplay
{
private $imageName;
public function __construct($imageName)
{
$this->imageName = $imageName;
}
public function show($content)
{ if($content=="image"){
$img=getimagesize($this->imageName);
switch ($img[2])
{
case 1:
$im =imagecreatefromgif($this->imageName);
break;
case 2:
$im =imagecreatefromjpeg($this->imageName);
break;
case 3:
$im =imagecreatefrompng($this->imageName);
break;
}
}
elseif ($content=="word") {
$im=imagecreatetruecolor(62,20);
$blackground=imagecolorallocate($im,0,0,0);
for($i=0;$i<200;$i++)
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);}
}
$word=array("新年","爱你","你的","开始");
$str=$word[rand(0,2)];
session_start();
$_SESSION['str']=$str;
$word=imagecolorallocate($im,255,255,255);
$str=iconv("gbk","utf-8","$str");
imagettftext($im,12,0,20,20,$word,'simkai.ttf',$str);
// header("content-type: image/jpeg");
Imagejpeg($im,'yzm.jpeg');
} }
这个是调用这个类的表单
<?php
require("class.php");
$image='xiaofl.jpg';
$imageDisplay = new ImageDisplay($image);
$imageDisplay->show("word");
?>
<form action="link.php" method="post" >
<table width="300" height="25" border="1"><tr><td width="160" height="19">输入验证码:
</td><td width="183">
<input type="text" name="name" size="6" maxlength="6"/>
</td><td><img src='yzm.jpeg' ></td></tr>
</table>
<div >
<input type="submit" name="name" value="提交"/></div>
</form>
这个提交表单link.php,在
php $name=$_POST['name'];
session_start();
if(!empty($_session['str'])&&($_session['str']==$name)){
echo "成功";
}
else
{
echo "失败";
}
但是这三个文件中我在class中建立了一个超全局变量session,但是在link.php,貌似提示
Notice: Undefined variable: _session in D:\php\fzclass\imageclass\link.php on line 11
并且显示失败 说我没有定义,这是怎么回事,是在类中无法使用session还是我写session的地方有错。请指教,天啊我都搞半天了郁闷啊,教教我吧,为什么我问题发上去以后看不到我的验证的图啊在我的电脑上都看的到啊怎么回事啊,我就在电脑前等答案,帮帮忙啊
