Jump to content

Image verification for registration form help


zhinigami

Recommended Posts

hi all,

 

I have tried download some example of captcha example for image validation like http://www.phpclasses.org/browse/package/3193.html or

http://www.digitalmidget.com/php_noob/captcha.php

 

But i still failed to successfully test it. I want to try to create it in a registration form which can be well function in both IE and Firefox. The sample i got from above can not view in IE or Firefox. the image didn't display out. I think it maybe caused by gd2_lib not be enabled? but I have found it is included in php.ini.

Can i have someone's guide about this?

 

Thank you

Link to comment
Share on other sites

To check to see if the gd library is installed, run a script with this in:

 

<?php
phpinfo();
?>

 

You should find a section titled, GD. You may find that you have an old version running, or perhaps you have don't have FreeType support, which may well be required for the above examples.

 

An alternative way of debugging the captcha scripts is to take out the lines which are similar to:

header("Content-type: image/png");
imagepng($im);

 

And add in the following lines, at the top of the script

ini_set('display_errors','On');
error_reporting(E_ALL);

 

Then navigate directly to the captcha script in your browser, and see if there are any errors being produced.

 

Link to comment
Share on other sites

Thanks for the guideline,

 

I have checked with phpinfo(), my current php version is 5.2.3 and I only found this:

 

Configure Command: cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"

 

which is related to gd.

 

Am i correct with this code in captcha_image.php?

<?php

session_start();

include("captcha_config.php"); // file with configuration data

 

 

ini_set('display_errors','On');

error_reporting(E_ALL);

 

// create random character code for the captcha image

$text = "";

$key_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // 0 1 O I removed to avoid confusion

$rand_max  = strlen($key_chars) - 1;

for ($i = 0; $i < $length; $i++) {

    $rand_pos  = rand(0, $rand_max);

    $text.= $key_chars{$rand_pos};

}

$_SESSION['captcha'] = $text; // save what we create

 

// center text in the 'box' regardless of rotation

function imagettftext_cr(&$img, $size, $angle, $x, $y, $content_color, $font, $text) {

    // retrieve boundingbox

    $bbox = imagettfbbox($size, $angle, $font, $text);

    // calculate deviation

    $dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0; // deviation left-right

    $dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0; // deviation top-bottom

    // new pivotpoint

    $px = $x-$dx;

    $py = $y-$dy;

    return imagettftext($img, $size, $angle, $px, $py, $content_color, $font, $text);

}

 

// get background image dimensions

$imgsize = getimagesize($background);

$height = $imgsize[1];

$width = $imgsize[0];

$xmax = $width - $sizex;

$ymax = $height - $sizey;

 

// create the background in memory so we can grab chunks for each random image

$copy = imagecreatefromjpeg($background);

 

// create the image

$img = imagecreatetruecolor($sizex,$sizey);

$content_color = imagecolorallocate($img, $red, $green, $blue);

 

// choose a random block (right size) of the background image

$x0 = rand(0,$xmax); $x1 = $x0 + $sizex;

$y0 = rand(0,$ymax); $y1 = $y0 + $sizey;

 

imagecopy($img,$copy, 0, 0, $x0, $y0, $x1, $y1);

$angle = $random * (5*rand(0,8) - 20); // random rotation -20 to +20 degrees

 

// add text to image once or twice (offset one pixel to emulate BOLD text if needed)

imagettftext_cr($img, $size, $angle, $sizex/2, $sizey/2-$yofs, $content_color, $font, $text);

if ($bold==1) {

    imagettftext_cr($img, $size, $angle, $sizex/2+1, $sizey/2-$yofs, $content_color, $font, $text);

}

 

 

//header ("content-type: image/png");

//imagepng ($img);

imagedestroy ($img);

?>

Link to comment
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.