Page 1 of 1

captcha headers

Posted: Wed Jan 03, 2007 6:29 am
by reecec
Hi



I have been using this captcha code but now it doesnt work. It just outputs the page url, i have had this before but it was a because the font want uploaded.



I think the reason for it outputing this is the header


Code: Select all

header('Content-Type: image/jpeg');

does any one know the reason for this suddenly not working



thanks reece

im using the captcha from this website

http://www.white-hat-web-design.co.uk/ ... aptcha.php


here is the code



Code: Select all

<?php
session_start();
 
/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 23/11/06
* Link: http://www.white-hat-web-design.co.uk/a ... aptcha.php
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the GNU General Public License 
* as published by the Free Software Foundation; either version 2 
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details: 
* http://www.gnu.org/licenses/gpl.html
*
*/
 
class CaptchaSecurityImages {
 
   var $font = 'monofont.ttf';
 
   function generateCode($characters) {
      /* list all possible characters, similar looking characters and vowels have been removed */
      $possible = '23456789bcdfghjkmnpqrstvwxyz';
      $code = '';
      $i = 0;
      while ($i < $characters) { 
         $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
         $i++;
      }
      return $code;
   }
 
   function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
      $code = $this->generateCode($characters);
      /* font size will be 75% of the image height */
      $font_size = $height * 0.75;
      $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
      /* set the colours */
      $background_color = imagecolorallocate($image, 255, 255, 255);
      $text_color = imagecolorallocate($image, 20, 40, 100);
      $noise_color = imagecolorallocate($image, 100, 120, 180);
      /* generate random dots in background */
      for( $i=0; $i<($width*$height)/3; $i++ ) {
         imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
      }
      /* generate random lines in background */
      for( $i=0; $i<($width*$height)/150; $i++ ) {
         imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
      }
      /* create textbox and add text */
      $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
      $x = ($width - $textbox[4])/2;
      $y = ($height - $textbox[5])/2;
      imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
      /* output captcha image to browser */
      imagejpeg($image);
      imagedestroy($image);
      $_SESSION['security_code'] = $code;
   }
 
}
 
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) ? $_GET['characters'] : '6';
 
header('Content-Type: image/jpeg');
$captcha = new CaptchaSecurityImages($width,$height,$characters);
 
?>

Posted: Wed Jan 03, 2007 8:43 am
by feyd
What does "it just outputs the page url" mean, exactly?

Posted: Wed Jan 03, 2007 9:07 am
by bokehman
feyd wrote:What does "it just outputs the page url" mean, exactly?
That's what happens when the image data is corrupt. When you call an image directly with Firefox if the image is corrupt it writes the URL of the image to the browser window instead of the image. Usually if you right click and select view source you will see the PHP error message if display errors is enabled.

Posted: Wed Jan 03, 2007 10:39 am
by reecec
bokehman wrote:
feyd wrote:What does "it just outputs the page url" mean, exactly?
That's what happens when the image data is corrupt. When you call an image directly with Firefox if the image is corrupt it writes the URL of the image to the browser window instead of the image. Usually if you right click and select view source you will see the PHP error message if display errors is enabled.

yea im using firefox just checked ie it has the missing image picture instead.


source is blank


not sure why its sundly started to happen


thanks reece

Posted: Wed Jan 03, 2007 11:21 am
by feyd
A blank page typically indicates that there was a fairly fatal error (and error display is off) or nothing happened to cause the code to output anything. Have you checked your error logs?

Posted: Thu Jan 04, 2007 11:31 am
by reecec
its working :!: dont know how it can work one day but not the next


thanks anyway