Hi Friends,
I am not sure whether this question can be posted here. I created a web application in PHP and the web app works fine in Chrome. But in Firefox most times it doesn't work(very few times it works..) Even when it works in Firefox the captcha image is not getting displayed.
Following is the code for generating the captcha image.
randomImage.php
---------------
<?php
///SETTINGS//////////////////////////////////////////////////
$height = 40;
$width = 160;
$textLength = 8; //AMOUNT OF NUMBERS AND LETTERS IN THE CODE
$fontSize = 23;
$noiseDots = 1500; // THE BIGGER THE NUMBER THE MORE NOISE YOU GET
$alphanum = "ABDFGHJKMNPRSTUVWXYZ23456789"; //SET OF CHARACTORS TO USE (0 1 O I ETC REMOVED)
//SETTINGS//////////////////////////////////////////////////
//create the random text and session
session_start();
$rand = substr(str_shuffle($alphanum), 0, $textLength);
$_SESSION['image_random_value'] = md5($rand);
// create the image
$my_image = imagecreatetruecolor($width, $height);
// use white as the background image
imagefill($my_image, 0, 0, 0xFFFFFF);
// the text color is random
$textColor = imagecolorallocate ($my_image, rand(50, 150), rand(50, 150), rand(50, 150));
// write the random string with a slight random tilt and a wavy font.
$font = 'marola.ttf';
imagettftext($my_image, $fontSize, rand(-2, 2), 5, 32, $textColor, $font, $rand);
//make some noise!
for ($c = 0; $c < $noiseDots; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
$cls = imagecolorallocate ($my_image, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($my_image, $x, $y, $cls);
}
// send several headers to make sure the image is not cached
// taken directly from the PHP Manual
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// send the content type header so the image is displayed properly
header('Content-type: image/jpeg');
// send the image to the browser
imagejpeg($my_image);
// destroy the image to free up the memory
imagedestroy($my_image);
?>
When the URL of the randomImage.php is typed in chrome the image gets displayed. But when the same URL is tried in Firefox I get the following error.
Bad Request
Your browser sent a request that this server could not understand.
Request header field is missing ':' separator.
alive
Please do let me know what the problem is. Thanks in advance for the help.
JVB.