This is the effect without opening the session (the picture of the verification code can be displayed normally)
This is the effect after opening the session (no picture is displayed)
Excuse me why is this
Source code respectfully
------------------ ----------------
<?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 );
?>
直奔十维2017-10-05 16:40:26
It should be automatically deleted, right? Temporary files.
In addition, you can also consider database storage session?
钟毅2017-10-04 14:03:31
I think you are not dealing with a problem that has gone wrong now. It is recommended that you start with a simple picture verification and think about it first. This is very necessary. Just remove other useless code. Already registered and verified user password. Let’s try this picture SESSION issue alone. Do you need to register a hidden domain?