USA: 1-253-242-9162.
India: 91-9823371776.
  • Home
  • Strategy
  • Services
  • Help & Support
  • Projects
  • Technologies We Use And Like
  • Lets Talk !
12
Sep
2011

A Quick Captcha Plugin

Posted by gis

Sometime s the fastest and the best Code snippets are “home-made” :-)

Below is a Captcha Snippet coded for a quick project, Use share

<?php
session_start();
/*

Quick Captcha Plugin by GlobalInteractiveSystems.com

Note:  Not tested, Use at your own risk.

*/

 

function create_image()
{
//Let’s generate a totally random string using md5
$md5_hash = md5(rand(0,999));
//We don’t need a 32 character long string so we trim it down to 5
$security_code = substr($md5_hash, 15, 5);

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

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

//Create the image resource
$image = imagecreate($width, $height);

//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);

//Make the background black

$fontfile = “./captcha.ttf”;

imagettftext ($image , 30, 0, 10, 36, $black ,$fontfile ,$security_code);

wave_area($image, $x, $y, $width, $height, rand(5,7), $period = 10);

//Tell the browser what kind of file is come in
header(“Content-Type: image/jpeg”);

//Output the newly created image in jpeg format
imagejpeg($image);

//Free up resources
ImageDestroy($image);
}

function wave_area(&$img, $x, $y, $width, $height, $amplitude = 10, $period = 10){

// Make a copy of the image twice the size

$height2 = $height * 2;

$width2 = $width * 2;

$img2 = imagecreatetruecolor($width2, $height2);

imagecopyresampled($img2, $img, 0, 0, $x, $y, $width2, $height2, $width, $height);

if($period == 0) $period = 1;

// Wave it

for($i = 0; $i < ($width2); $i += 2)

imagecopy($img2, $img2, $x + $i – 2, $y + sin($i / $period) * $amplitude, $x + $i, $y, 2, $height2);

// Resample it down again

imagecopyresampled($img, $img2, $x, $y, 0, 0, $width, $height, $width2, $height2);

imagedestroy($img2);

}

create_image();
?>

Posted in: PHP
2 Comments
Tags: gd, php, spam block

{2 Responses to “A Quick Captcha Plugin”}

  1. November 22, 2011 at 12:39 am

    Hey! My brother has recommended me to have a look at your site. And I’d like to say that I really like what you’re posting here.

    Reply
    Brent Curimao
  2. January 9, 2012 at 1:29 am

    This aitcrle went ahead and made my day.

    Reply
    Laicee

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • {Free Consultation}

    Get a free quote on your next project

    Contact Us

  • {24×7 Support}

    support.globalinteractivesystems.com
  • {Recent}

    • .htaccess Tricks
    • A Quick Captcha Plugin
    • Registering A Domain Name
    • Moving a wordpress site
    • Landing Pages, what are they?
Copyright © Global Interactive Systems. Rights Reserved.