PHP Capcha image woeking on localhost but not online

I have implemented a captcha image in my site, it was working good eno

Page 1 of 1

2 Replies - 1456 Views - Last Post: 26 May 2009 - 05:52 AM Rate Topic: -----

#1 yasirlatif  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-May 09

PHP Capcha image woeking on localhost but not online

Posted 25 May 2009 - 10:25 PM


<?php
session_start(); //MUST START SESSION
$string_length=5; //NUMBER OF CHARS TO DISPLAY
$rand_string='';
for($i=0;$i<$string_length;$i++)
{
  //PICK A RANDOM UPPERCASE LETTER USING ASCII CODE
  $rand_string.=chr(rand(65,90));
}//IMAGE VARIABLES
$width=100;
$height=36;
//INIT IMAGE
$img=imagecreatetruecolor($width, $height);
//ALLOCATE COLORS
$black=imagecolorallocate($img, 255, 255, 255);
$gray=imagecolorallocate($img, 94, 127,194);
imagefilledrectangle($img, 0, 0, $width, $height, $gray);
//REPLACE THIS WITH THE FONT YOU UPLOAD
$font='BELLB.TTF';
$font_size=16;
//CALC APPROX LOCATION FOR TEXT
$y_value=($height/2)+($font_size/2);
$x_value=($width-($string_length*$font_size))/2;
//DRAW STRING USING TRUE TYPE FUNCTION
imagettftext($img, $font_size, 0, $x_value,
	$y_value, $black, $font, $rand_string);
$_SESSION['encoded_captcha']=md5($rand_string);
//OUTPUT IMAGE HEADER AND SEND TO BROWSER
header("Content-Type: image/png");
imagepng($img);
?>


Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: PHP Capcha image woeking on localhost but not online

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: PHP Capcha image woeking on localhost but not online

Posted 25 May 2009 - 10:53 PM

Does the host you are uploading it to have GD enabled? Secondly, make sure there is no space before the script. The first line will have to be your <?php. Third, make sure that BELLB.TTF is in the same directory as this script.

So check to make sure the host has that GD packaged installed (if you are getting some error about functions not recognized) and then make sure you have nothing printing before the script (even spaces) and that you have the font file in the same folder as the script.

This should fix the problems. :)
Was This Post Helpful? 0
  • +
  • -

#3 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: PHP Capcha image woeking on localhost but not online

Posted 26 May 2009 - 05:52 AM

This exact same problem was solved previously.
I suggest taking a look at this thread and going through some of the steps.

Yours,
Shane~
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1