I wrote a small procedural script (OO would have been better but time constraints dictated otherwise) that produces a captcha image
Online: http://valsignalandet.com/images/captcha.php
However, while the images are being produced, the text appears in random colors from black to white to gray, and I can't seem to control that in spite of hard-coding the background and foreground colors, furthermore, the text also randomly appears within the image positioned differently each time.
Here is the code:
<?php
session_start();
if (!function_exists('randstring')) @include('/users/ppowell/web/functions.inc.php');
if (!$_SESSION['rand_code']) {
$_SESSION['rand_code'] = @randstring(6);
}
$text = $_SESSION['rand_code'];
$image = @imagecreatetruecolor(90, 30);
$bgColor = @imagecolorallocate($image, 180, 180, 180);
$fgColor = @imagecolorallocate($image, 75, 75, 75);
$width = (@imagesx($image) - 7.5 * $text) / 2;
$height = (@imagesy($image) - 7.5) / 2;
@imagefilledrectangle($image, 0, 0, 90, 30, $bgColor);
@imagestring($image, rand(3, 5), $width, $height, $text, $fgColor);
unset($_SESSION['rand_code'], $text);
session_unregister('rand_code');
header("Content-type: image/png");
@imagepng($image);
@imagedestroy ($image);
?>
Any ideas as to why this is happening?
Thanks