I am wondering why the characters in the image generated by this script do not match the characters set for the session. I can not find why this is so, if someone can help, that would be great. Thanks, Lee.
$font = 'wordpress/wp-content/themes/boldy/fonts/SF Juggernaut Bold.ttf';
$lineCount = 20;
$fontSize = 19;
$height = 38;
$width = 120;
$img_handle = imagecreate ($width, $height) or die ("Cannot Create image");
$backColor = imagecolorallocate($img_handle, 242, 242, 242);
$lineColor = imagecolorallocate($img_handle, 207, 207, 207);
$txtColor = imagecolorallocate($img_handle, 95, 95, 95);
$string = "bcdefghijklmopqrstwxyz023456789";
for($i=0;$i<6;$i++){
$pos = rand(0,36);
$str .= $string{$pos};
}
$textbox = imagettfbbox($fontSize, 0, $font, $str) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($img_handle, $fontSize, 0, $x, $y, $txtColor, $font , $str) or die('Error in imagettftext function');
for($i=0;$i<$lineCount;$i++){
$x1 = rand(0,$width);$x2 = rand(0,$width);
$y1 = rand(0,$width);$y2 = rand(0,$width);
imageline($img_handle,$x1,$y1,$x2,$y2,$lineColor);
}
header('Content-Type: image/jpeg');
imagejpeg($img_handle,NULL,100);
imagedestroy($img_handle);
session_start();
$_SESSION['img_number'] = $str;
UPDATE: . When testing, I noticed that the first time the image is loaded, the session is NOT established, so when the image is updated, the session is established with the last $ str value