0

I'm trying to render captcha Image on a page as follows:

<img src="part/captcha_image.php?rand=<?php echo rand(); ?>" id='captchaimg' alt="captcha image">

Image is returned in captcha_image.php with:

header('Content-Type: image/jpeg'); // defining the image type to be shown in browser widow
imagejpeg($image); //showing the image

And on windows machine on xampp it's showing without any problems but on linux with manual apache2 installation image doesn't renders and in browser's developer's tools i see following errors:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) (Shown on chrome and firefox)

http://localhost/app/part/captcha_image.php?rand=1653484771 Failed to load resource: net::ERR_CACHE_MISS (only shown on chrome)

What am I missing?

Disper
  • 725
  • 12
  • 28
  • You're using chrome, correct? See: http://stackoverflow.com/questions/26408931/bizarre-error-in-chrome-developer-console-failed-to-load-resource-neterr-ca & https://code.google.com/p/chromium/issues/detail?id=424599 – wolfemm Nov 03 '14 at 21:26
  • That's correct. I've tested my page on firefox and edited my question with results (ERR_CACHE_MISS is not shown on firefox) – Disper Nov 03 '14 at 21:40
  • 2
    Did you install php with gd module? – Cheery Nov 03 '14 at 21:54
  • @Cheery , good sir you just saved my day! `sudo apt-get install php5-gd && sudo service apache2 restart` fixed my problem. – Disper Nov 03 '14 at 21:59

2 Answers2

1

It sounds like this question has been answered in the comments. For a problem like this, be sure to turn on detailed error reporting in PHP's configuration, and hit the URL for an image directly in your browser address bar.

If you do that, and in fact the problem is that you needed gd and gd is missing, then the error page will tell you so.

Brendan Kidwell
  • 876
  • 9
  • 15
  • Thank you for your advice! Am I correct that `error_reporting(-1);` function call turns on detailed reporting? – Disper Nov 04 '14 at 07:05
  • Yes that's what I meant. But I just keep it on globally using the appropriate setting in `php.ini`, in my development instance of the project. – Brendan Kidwell Nov 05 '14 at 18:27
0

As @Cheery suggested in comments I was missing gd module which is responsible for creation and manipulation of image files . Command sudo apt-get install php5-gd && sudo service apache2 restart fixed my problem.

Disper
  • 725
  • 12
  • 28