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

  • Home
  • SEARCH
  • 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 6716743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:46:13+00:00 2026-05-26T08:46:13+00:00

i have following captcha code: <?php class CaptchaView extends View { private $fontsDir =

  • 0

i have following captcha code:

<?php

class CaptchaView extends View
{
    private $fontsDir = 'captcha_resources/fonts/';
    private $backgroundsDir = 'captcha_resources/backgrounds/';
    private static $dirCache = array();

    public function render($controller)
    {
        $code = $controller->viewVars["code"];

        /**
         * The next part is orginnaly written by ted from mastercode.nl and modified for using in this mod.
         **/

        header("content-type:image/png");
        header('Cache-control: no-cache, no-store');

        $width = 100;
        $height = 30;

        $img = imagecreatefrompng(self::backgroundImage());

        // add noise
        for ($i = 0; $i < 1; $i++) {
            $horizontal_progress = 0;
            $vertical_pos = rand(1, $height / 2);
            do {
                $horizontal_step_size = floor(rand(1, $width / 5));

                imageline($img, $horizontal_progress, $vertical_pos, ($horizontal_progress += $horizontal_step_size), ($vertical_pos = rand(1, $height)), self::color("tekst"));
            } while ($horizontal_progress < $width);
        }

        $background = imagecolorallocate($img, self::color("bg"), self::color("bg"), self::color("bg"));

        for ($g = 0; $g < 30; $g++) {
            $t = rand(10, 20);
            $t = $t[0];

            $ypos = rand(0, $height);
            $xpos = rand(0, $width);

            $kleur = imagecolorallocate($img, self::color("bgtekst"), self::color("bgtekst"), self::color("bgtekst"));

            imagettftext($img, self::size(), self::move(), $xpos, $ypos, $kleur, self::font(), $t);
        }

        $stukje = $width / (strlen($code) + 3) + 5;

        for ($j = 0; $j < strlen($code); $j++) {
            $tek = $code[$j];
            $ypos = rand(23, 27);
            $xpos = $stukje * ($j + 1) - 5;

            $color2 = imagecolorallocate($img, self::color("tekst"), self::color("tekst"), self::color("tekst"));

            imagettftext($img, self::size(), self::move(), $xpos, $ypos, $color2, self::font(), $tek);
        }

        imagepng($img);
        imagedestroy($img);
    }
    /**
     * Some functions :)
     * Also orginally written by mastercode.nl
     **/

    /**
     * Function to create a random color
     * @auteur mastercode.nl
     * @param $type string Mode for the color
     * @return int
     **/
    private static function color($type)
    {
        switch ($type) {
            case "bg":
                $color = rand(224, 255);
                break;

            case "tekst":
                $color = rand(0, 127);
                break;

            case "bgtekst":
                $color = rand(200, 224);
                break;

            default:
                $color = rand(0, 255);
                break;
        }
        return $color;
    }

    /**
     * Function to ranom the size
     * @auteur mastercode.nl
     * @return int
     **/
    private static function size()
    {
        return rand(18, 22);
    }

    /**
     * Function to random the posistion
     * @auteur mastercode.nl
     * @return int
     **/
    private static function move()
    {
        return rand(-22, 22);
    }

    /**
     * Function to return a ttf file from fonts map
     * @auteur mastercode.nl
     * @return string
     **/
    function randomFileByExt($dir, $ext)
    {
        $f = opendir($dir);

        if (empty(self::$dirCache[$dir])) {
            $ar = array();
            while (($file = @readdir($f)) !== false) {
                if (!in_array($file, array('.', '..')) && substr_compare($file, $ext, -strlen($ext)) == 0) {
                    $ar[] = $file;
                }
            }

            self::$dirCache[$dir] = $ar;
        } else {
            $ar = self::$dirCache[$dir];
        }

        if (count($ar)) {
            $i = rand(0, (count($ar) - 1));
            return $dir . $ar[$i];
        }
    }

    private function backgroundImage()
    {
        return self::randomFileByExt(Config::get("VIEWS_PATH") . $this->backgroundsDir, ".png");
    }

    private function font()
    {
        return self::randomFileByExt(Config::get("VIEWS_PATH") . $this->fontsDir, ".ttf");
    }
}

actually it display 4 letters with a disturbed background

i want block some spam bot them i think to modify code to increase security increasing number of letters
can you tell me how to modify it to display 6 letters instead of 4?

  • 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-26T08:46:13+00:00Added an answer on May 26, 2026 at 8:46 am

    1) Best solution is to implement existing Captcha like reCaptcha or so..

    • docs : http://code.google.com/intl/en_EN/apis/recaptcha/intro.html
    • PHP : http://code.google.com/intl/en_EN/apis/recaptcha/docs/php.html

    2) To modify your code to push 6 instead of 4 letters edit part of code like this:

    $stukje = $width / (strlen($code) + 5) + 5; //instead of  "+3) +5;"
    

    should do the trick, but I can’t test it, since I don’t know in which mod it was used (what CMS, PHP Framework,…)

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

Sidebar

Related Questions

Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
I have following code: public class reader extends Activity { WebView mWebView; String mFilename;
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following code: class EntityBase (object) : __entity__ = None def __init__ (self)
I have following code created dynamically with php. What I want to do is
I have following Code Block Which I tried to optimize in the Optimized section
I have following classes. class A { public: void fun(); } class B: public
I have following wrapper to help me manage the wcf client lifetime: public class
I have following property in my Model Metadata class: [Required(ErrorMessage = Spent On is
i have following problem To decode the Biquinary code use the number 5043210. At

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.