It is currently Thu Sep 09, 2010 7:15 am
Index  •  FAQ  •  Search

All times are UTC + 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Again captcha
PostPosted: Mon Jul 20, 2009 5:42 pm 
User avatar
User's Group : S.U.S.T

Joined: Mon Mar 02, 2009 3:27 pm
Posts: 14
You've already seen a post about captcha.If not i encourage you to see it.I've learned about captcha after that post.Thuough it is pretty simple captcha script.If you try to run that script you will notice that it is not like others where they have different type of background color,different type of font,noise.So in this post i will try to figure that.

Code:
<?php
session_start();


function captcha($length) {

    // generate a totally random string using md5
    $rd = md5(rand(0, 999)); 
   
    // We don't need a 32 character long string so we trim it down to 5  because md5 will return a long string
    $code = substr($rd, 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 - 60), ($rgb2 - 60), ($rgb3 - 60));

    // Make the background colour
    imagefill($image, 0, 0, $background); 
        for ($i = 0; $i < 10; $i++) {
$rx1 = rand(0,$width);
$rx2 = rand(0,$width);
$ry1 = rand(0,$height);
$ry2 = rand(0,$height);
$rcVal = rand(0,255);
$rc1 = imagecolorallocate($image,
rand(0,255),
rand(0,255),
rand(100,255));
//giving noise
imageline ($image, $rx1, $ry1, $rx2, $ry2, $rc1);
}

    // 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);
        }
         
imagettftext($image, rand(14, 20), $angle, ($i * 25), 30, $text, "font/LucidaBrightDemiItalic.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); 
}
/* pass  how many cahracter do you want your user can see*/

captcha(6);//i have pass 6 where user
?>


You see "LucidaBrightDemiItalic.ttf".I have this font in font directory.This will be our font style of captcha.You can give your own.But remember you have to put font file in the directory or Sub-directory where your php file will stay.You can include it wherever you want.And make a call with captcha(6); this.So,thst's it and
"have a good programming".


Offline
 Profile  
Top 
 Post subject: Re: Again captcha
PostPosted: Tue Jul 21, 2009 7:51 pm 
User avatar
User's Group : S.U.S.T

Joined: Mon Mar 02, 2009 10:07 am
Posts: 28
:thumbsup: gR8 POST!!!

_________________
Image


Offline
 Profile  
Top 
 Post subject: Re: Again captcha
PostPosted: Sun Jul 26, 2009 9:58 pm 
User avatar
User's Group : S.U.S.T

Joined: Mon Mar 02, 2009 3:27 pm
Posts: 14
@cse031sust02 Thanks Bhaia. :pc:


Offline
 Profile  
Top 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: