Forum Moderators: phranque

Message Too Old, No Replies

WebApp working with CHrome but not with Firefox

         

bhaceg

7:08 pm on Jun 2, 2010 (gmt 0)

10+ Year Member



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.

jdMorgan

1:27 am on Jun 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fire up the "Live HTTP Headers" add-on for Firefox, and look at the HTTP headers for the missing ":" in the HTTP Request header that your server is complaining about...

It is likely caused by something the server sent earlier, because I'm fairly sure that Firefox --on its own-- won't send malformed headers. However, as an example, if you mis-formatted the Last-Modified header time-string (missing/mis-matched quotes, maybe?), and Firefox tried to send that timestamp back to your server in a subsequent If-Modified-Since request header, then that could cause this kind of problem.

This is only intended as a illustrative example, not as a guess at what might be wrong, but do check the headers.

Jim

bhaceg

4:26 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Thanks for your reply Jim. Will try the Live HTTP header add on. Meanwhile, I found where the problem occurs. And also I found a fix but a wrong fix for the problem. This happens when an image is tried to be displayed using the <img /> tag.

And previously the Apache web server was listening only on port 443 not on port 80. When I changed the config file to make the apache listen on both 443 and port 80 the problem got solved. But I don't want to listen on port 80 at all. Is there some relationship between port 80 and image display in html.

Thanks,
Bharath.

jdMorgan

1:16 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps the images are being requested via http, but being included on an https page? The Live headers add-on will make that obvious, along with many other potential problems... It --or a similar tool-- is basic Webmaster kit.

Jim