TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-02-2009, 02:16 PM   #1 (permalink)
The Wanderer
 
ebuoe's Avatar
 
Join Date: May 2009
Location: lagos, nigeria
Posts: 13
Thanks: 9
ebuoe is on a distinguished road
Default Captcha image isn't showing

php Code:
session_start();
//--------------------
// CAPTCHA Function
//--------------------
function captcha($length = 6) {
    $length = isset($_GET['chars']) ? $_GET['chars'] : 6;
     
    // Let's generate a totally random string using md5
    $hash = md5(rand(0, 999))
    // We don't need a 32 character long string so we trim it down to 5 
    $code = substr($hash, 15, $length)

    // Set the session to store the security code
    $_SESSION["captcha"] = $code;

    // Set the image width and height
    $width = 200;
    $height = 50;

    // Create the image resource 
    $image = imagecreate($width, $height);
    // Random RGB colours
    $rgb1 = rand(0, 255);
    $rgb2 = rand(0, 255);
    $rgb3 = rand(0, 255);
     
    $background = imagecolorallocate($image, $rgb1, $rgb2, $rgb3);
    $text = imagecolorallocate($image, ($rgb1 - 50), ($rgb2 - 50), ($rgb3 - 50));

    // Make the background colour
    imagefill($image, 0, 0, $background)

    // Add randomly generated string in the image
    for($i = 1; $i <= $length; $i++) {
        $counter = rand(1, 2);
         
        if ($counter == 1) {
            $angle = rand(0, 45);
        }
        if ($counter == 2) {
            $angle = rand(315, 360);
        }
         
       /*problem*/ imagettftext($image, rand(14, 20), $angle, ($i * 25), 30, $text, "templates/ChalkboardBold.ttf", substr($code, ($i - 1), 1));
    }

    // Add a border
    imagerectangle($image, 0, 0, $width - 1, $height - 1, $text)
 
    // Tell the browser what kind of file is come in 
    header("Content-Type: image/png")

    // Output the newly created image in jpeg format 
    imagepng($image);
   
    // Free up resources
    imagedestroy($image)
}
!isset($_GET['chars']) ? captcha() : captcha($_GET['chars']);

I got this code from this site but it shows this error in IE:

Quote:
Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\wamp\www\arrays\learningfiles.php on line 102
‰PNG IHDRÈ2#Ÿ¢PLTEÕš£hO¹¾„+IDATxœcø 040`Œ£2£2£2£2C\gÉ ÓIÿûáo«IEND®B`‚
Quote:
This on Firefox
The image “http://localhost/learningfiles/captcha.php” cannot be displayed, because it contains errors.
I think the problem is from the line where I marked problem. How do I solve this, please?

Last edited by Wildhoney : 06-02-2009 at 03:35 PM.
ebuoe is offline  
Reply With Quote
Old 06-02-2009, 06:16 PM   #2 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

does "templates/ChalkboardBold.ttf" exists? If not place it there. Or show to another falid font file.
Further - which line is Nr.102?
Sakakuchi is offline  
Reply With Quote
Old 11-12-2012, 07:40 AM   #3 (permalink)
The Contributor
 
Join Date: Oct 2012
Posts: 46
Thanks: 0
ww628815 is on a distinguished road
Default

Jordan Shoes For Sale are giving more importance to shoes which gives them comfort while walking or running. Jordan Shoes for sale, Discount Jordan shoes, Buy 2012 New Jordans sale chiropodist will suggest which sort and elegance of shoes you must wear avoiding developing common problems of the feet and possible flattening in the arches from the feet. Discount Jordan Shoes molded arch supports might be fitted inside shoes to relieve aching of the feet if you stand or walk.
ww628815 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Image Reflections in PHP Rendair Advanced PHP Programming 17 11-30-2011 08:41 AM
help me with Captcha image sharma.9.pooja General 5 06-29-2008 03:19 AM
[Tutorial] CAPTCHA CMellor Script Giveaway 13 06-01-2008 08:33 PM
The Big GD Guide - Part 2 Rendair Advanced PHP Programming 3 03-07-2008 12:14 AM


All times are GMT. The time now is 01:24 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design