
写了一个php验证码,单独运行可以,引用就显示错误
checkcode.php文件如下代码:<?php//画出验证码$checkCode="";for($i=0;$i<4;$i++){$checkCode.=dechex(...
checkcode.php文件如下代码:<?php //画出验证码 $checkCode=""; for ($i=0;$i<4;$i++){ $checkCode.=dechex(rand(1,15)); } //创建画布 $image=imagecreatetruecolor(110,30); //存入session session_start(); $_SESSION['checkcode']=$checkCode; //设置颜色 $red=imagecolorallocate($image,255,255,255); //画出干扰线 for($i=0;$i<20;$i++){ imageline($image,rand(0,110),rand(0,110),rand(0,30),rand(0,30),imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255))); }test.php如下代码:显示验证码<img src="checkcode.php" /> imagestring($image,rand(5,8),rand(0,60),rand(0,10),$checkCode,$red); //输出到页面 ob_clean(); header("content-type:image/png"); imagepng($image); //销毁图片 imagedestroy($image);?>
这段是放另外的,复制错误了
test.php如下代码:
显示验证码<img src="checkcode.php" /> 展开
这段是放另外的,复制错误了
test.php如下代码:
显示验证码<img src="checkcode.php" /> 展开
1个回答
2016-06-18
展开全部
你应该这样用:
checkcode.php:
<?php
//画出验证码
$checkCode="";
for ($i=0;$i<4;$i++){
$checkCode.=dechex(rand(1,15));
}
//创建画布
$image=imagecreatetruecolor(110,30);
//存入session
session_start();
$_SESSION['checkcode']=$checkCode;
//设置颜色
$red=imagecolorallocate($image,255,255,255);
//画出干扰线
for($i=0;$i<20;$i++){
imageline($image,rand(0,110),rand(0,110),rand(0,30),rand(0,30),imagecolorallocate($image,rand(0,255),rand(0,255),rand(0,255)));
}
imagestring($image,rand(5,8),rand(0,60),rand(0,10),$checkCode,$red);
//输出到页面
ob_clean();
header("content-type:image/png");
imagepng($image);
//销毁图片
imagedestroy($image);
?>
test.php:
显示验证码<img src="checkcode.php" />
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询