Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6726807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:58:17+00:00 2026-05-26T09:58:17+00:00

I made a captcha class to generate a captcha. for some reason I can

  • 0

I made a captcha class to generate a captcha. for some reason I can only get the image to display if I make an instance of the class in the class file itself. otherwise I get nothing. In firebug I see the file being included but its being sent as html despite I used header("Content-type: image/png");
class.captcha.php

<?php
class captcha
{

    public $length=4;
    public $width=150;
    public $height=50;
    public $allowedChar='1234569ACEFGHJKMNPQRSTXZ';
    public $font='Arcade.ttf';
    public $fontSize=25;
    public $fontRed=0;
    public $fontGreen=0;
    public $fontBlue=104;
    public $backgroundRed=204;
    public $backgroundGreen=204;
    public $backgroundBlue=255;
    public $noiseRed=0;
    public $noiseGreen=0;
    public $noiseBlue=104;
    public $noisePercent=5;

    /*
    ** @RETURN IMAGE raw image of captcha
    */
    public function create($name)
    {
        //string
        for ($i=0;$i<$this->length;$i++) 
        {$captcha.= $this->allowedChar[mt_rand(0, strlen($this->allowedChar))];}

        //image
        $img=imagecreatetruecolor($this->width, $this->height);
        //colors
        $bgColor=imagecolorallocate($img, $this->backgroundRed, $this->backgroundGreen, $this->backgroundBlue);
        $fontColor=imagecolorallocate($img, $this->fontRed, $this->fontGreen, $this->fontBlue);
        $noiseColor=imagecolorallocate($img, $this->noiseRed, $this->noiseGreen, $this->noiseBlue);
        imagefilledrectangle($img,0,0,$this->width+1,$this->height+1,$bgColor);
        //text
        for($i=0;$i<strlen($captcha);$i++)
        {
            $rotate=rand(0, 80)-40;
            $offX=$i*$this->fontSize+rand($this->fontSize, $this->fontSize*1.2);
            $offY=$this->fontSize+rand($this->fontSize/2, $this->fontSize);;
            $letter=$captcha[$i];
            imagettftext($img, $this->fontSize, $rotate, $offX, $offY, $fontColor, $this->font, $letter);
        }
        //add noise
        for($i=0;$i<$this->height*$this->width*($this->noisePercent/100);$i++)
        {
            //noise
            $x=rand(0, $this->width);
            $y=rand(0, $this->height);
            imagesetpixel($img, $x, $y, $noiseColor);
        }
        $_SESSION[$name]=md5($captcha);
        return $img;
    }
}
?>

captcha.contact.php

<?php
session_start(); 
include('class.captcha.php');
$c=new captcha;
header("Content-type: image/png"); 
imagepng($c->create('contactCaptcha'));
?>

link to above if it helps http://yamikowebs.com/_test/_php/class.captcha.php
the error is The image “http://yamikowebs.com/_test/_php/captcha.contact.php” cannot be displayed because it contains errors.
if i put the contents of capture.contact.php at the end of class.captcha.php it works no problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:58:18+00:00Added an answer on May 26, 2026 at 9:58 am

    contact.captcha.php

    <?php
    include('class.captcha.php');
    $c=new captcha;
    header("Content-type: image/png"); 
    imagepng($c->create('contactCaptcha'));
    ?>
    

    session_start() sends header information so once removed it started working fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a class. This is the h file. // MyClass.h #import <Foundation/Foundation.h> @interface
I've made my own captcha class in PHP, just to learn. It's ok, working
i made a file to print out the image file with W and H
OK, I'm actually calling some java middleware that returns a captcha image. The captcha
Made some 2 buttons on my blog so users can go the next or
I'm trying to add a captcha to a site somebody else has made. I've
Made solution change: I am trying to display a html table of data.. In
I made a class from Linq to SQL Clasees with VS 2008 SP1 Framework
I made a Java Applet with some Standard GUI Components on it. I used
I made a discovery some time back. Just follow these steps: Create a .doc/.xls/.ppt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.