Jump to content

Recommended Posts

Hi, I am making a CAPTCHA image.  I am pretty sure the code I have is correct, but I am getting these error messages when I run the script.  I use GoDaddy for hosting.  The font that I reference in the script is in the root directory with the script.  Any ideas? 

 

Thanks,

Craig

 

------------

 

Warning: imagefilledrectangle(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 19

 

Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22

 

Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22

 

Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22

 

Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22

 

Warning: imageline(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 22

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagesetpixel(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 27

 

Warning: imagettftext() expects parameter 1 to be resource, null given in /home/content/68/6372768/html/captcha.php on line 30

 

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/68/6372768/html/captcha.php on line 35

 

 

<?php
session_start();

  // Set some important CAPTCHA constants
  define('CAPTCHA_NUMCHARS', 6);  // number of characters in pass-phrase
  define('CAPTCHA_WIDTH', 100);   // width of image
  define('CAPTCHA_HEIGHT', 25);   // height of image

  // Generate the random pass-phrase
  $pass_phrase = "";
  for ($i = 0; $i < CAPTCHA_NUMCHARS; $i++) {
    $pass_phrase .= chr(rand(97, 122));
  }

  // Store the encrypted pass-phrase in a session variable
  $_SESSION['pass_phrase'] = sha1($pass_phrase);

  // Create the image
  $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);

  // Set a white background with black text and gray graphics
  $bg_color = imagecolorallocate($img, 255, 255, 255);     // white
  $text_color = imagecolorallocate($img, 0, 0, 0);         // black
  $graphic_color = imagecolorallocate($img, 64, 64, 64);   // dark gray

  // Fill the background
  imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color);

  // Draw some random lines
  for ($i = 0; $i < 5; $i++) {
    imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color);
  }

  // Sprinkle in some random dots
  for ($i = 0; $i < 50; $i++) {
    imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphic_color);
  }

  // Draw the pass-phrase string
  imagettftext($img, 18, 0, 5, CAPTCHA_HEIGHT - 5, $text_color, 'Courier New Bold.ttf', $pass_phrase);

  // Output the image as a PNG using a header
  header("Content-type: image/png");
  imagepng($img);

  // Clean up
  imagedestroy($img);
?>

Link to comment
https://forums.phpfreaks.com/topic/210030-captcha/
Share on other sites

Another note, I just did a php info and all my GD stuff seems to be enabled.

 

GD Support enabled

GD Version bundled (2.0.34 compatible)

FreeType Support enabled

FreeType Linkage with freetype

FreeType Version 2.2.1

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

Link to comment
https://forums.phpfreaks.com/topic/210030-captcha/#findComment-1096165
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.