PHP Snippet - custom captcha

Need a quick and dirty captcha?

session_start();

        $str = str_shuffle(‘abcdefghijklmnopqrstuvwxyz0123456789′);
        $substr = substr($str, 0, 6);
        $im = imagecreate(60, 25);
        // white background and blue text
        $bg = imagecolorallocate($im, 255, 255, 255);
        $textcolor = imagecolorallocate($im, 0, 0, 0);
        // write the string at the top left
        imagestring($im, 5, 2, 4, $substr, $textcolor);
        // output the image
        header(“Content-type: image/png”);
        imagepng($im);

Should give you a simple image (but easily decipherable by OCR Readers )

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.