登录  /  注册
图片验证码使用session以后报错
富贵
富贵 2017-10-04 01:31:24
[PHP讨论组]

这是没开session的效果(可以正常显示验证码的图片)

---------------------------华丽丽的分割线------------------------------------------


这是打开session以后的效果(没有图片显示)


----------------------------------------------------------------------------

请问这是为什么

源码敬上

----------------------------------

<?php

session_start();

$width = 300;

$height = 100;

$img = imagecreatetruecolor($width,$height);

$white = imagecolorallocate($img, 255, 255, 255);

$red = imagecolorallocate($img, 255, 0, 0);

imagefilledrectangle($img, 0, 0, $width, $height, setColor($img));

function setColor($img)

{

return imagecolorallocate($img,getColor(),getColor(),getColor());

}

function getColor()

{

return mt_rand(0,255);

}

function setNum($a,$b)

{

return mt_rand($a,$b);

}

function getCode()

{

return $string = join('',array_rand(array_flip(array_merge(range(0,9),range('a','z'),range('A','Z'))),4));

}

$str = getCode();

$_SESSION['verifycode'] = $str;

for($i=0;$i<4;$i++)

{

$size = setNum(20,50);

$angle = setNum(-15,15);

$x = ($width/4)*$i+mt_rand(1,9);

$y = mt_rand(($height/2),$height);

$color = setColor( $img );

$fontfile = './fonts/MSYH.ttf';

$text = mb_substr(getCode(),$i,1,'utf-8');

imagettftext($img, $size, $angle, $x, $y, $color, $fontfile, $text);

}

for($i=0;$i<1500;$i++)

{

imagesetpixel($img, mt_rand(0, $width), mt_rand(0, $height), setColor($img));

}

for($i=0;$i<3;$i++)

{

imageline($img, mt_rand(0, $width), mt_rand(0,$height), mt_rand(0, $width), mt_rand(0,$height), setColor($img));

}

for($i=0;$i<3;$i++)

{

$cx = mt_rand(0, $width);

$cy = mt_rand(0, $height);

$width = mt_rand(0, $width/2);

$height = mt_rand(0, $height/2);

$start = mt_rand(0, 360);

$end = mt_rand(0, 360);

$color = setColor($img);

imagearc($img, $cx, $cy, $width, $height, $start, $end, $color);

}

header('content-type:image/jpeg');

imagejpeg( $img );

imagedestroy( $img );

?>



富贵
富贵

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号