Jump to content

Creation of captcha

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
21 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Hey there!

I was thinking.. there are many users who have asked from me.. how to create a captcha or that image where are those random numbers or letters.. so i thought i'll make one.. :)

<?php
header('Content-type: image/jpg');

header('Content-type: image/jpg'); this means that it will be a jpg image (because our background will be jpg)

$im = imagecreatefromjpeg ("image.jpg");

$im = imagecreatefromjpeg ("image.jpg"); It will take image.jpg for our image's background
$rand1 = rand(1,255);
$rand2 = rand(1,255);
$rand3 = rand(1,255);
$color = imagecolorallocate($im, $rand1, $rand2, $rand3);

$rand1 = rand(1,255);-
$rand2 = rand(1,255);- - Those variables will create a random number from 1 to 255 so we will have a random color for our text
$rand3 = rand(1,255);-
$color = imagecolorallocate($im, $rand1, $rand2, $rand3); - This will create a color for our text

$text = rand(1000, 9999);
$font = 'text-font.otf';
$size = 30;

$text = rand(1000, 9999); - This will create a random number between 1000 and 9999
$font = 'text-font.otf'; - This will be our font
$size = 30; - It will be font's size

imagettftext($im, $size, 0, 70, 45, $color, $font, $text);
imagejpeg($im);
imagedestroy($im);

This will put your info together to form a image :) it's that simple..

Here's the full code:

<?php
header('Content-type: image/jpg');
$im = imagecreatefromjpeg ("image.jpg");
$rand1 = rand(1,255);
$rand2 = rand(1,255);
$rand3 = rand(1,255);
$color = imagecolorallocate($im, $rand1, $rand2, $rand3);
$text = rand(1000, 9999);
$font = 'text-font.otf';
$size = 30;
imagettftext($im, $size, 0, 70, 45, $color, $font, $text);
imagejpeg($im);
imagedestroy($im);
?> 

I attached this script's files also :) It includes text-font.oft, image.jpg and index.php files :)

I'll add the part 2 for it also :) tomorrow i guess

Attached Files


Edited by Jaan, 29 April 2008 - 02:26 AM.


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Nice tutorial. +rep.

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
yay.. thank you :)

#4
dreamcoder

dreamcoder

    Newbie

  • Members
  • Pip
  • 1 posts
Love it, thanks

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
This might not be safe - ya know, these types of CAPTCHAs have been broken. :(
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts

Xav said:

This might not be safe - ya know, these types of CAPTCHAs have been broken. :(

Yes, but about 75% of the time they work. Which is a lot better than not having one.

#7
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
True, although it's still better to have a safe one. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#8
Blizz

Blizz

    Newbie

  • Members
  • Pip
  • 1 posts
thank you :)

#9
Guest_Jaan_*

Guest_Jaan_*
  • Guests
You're welcome :)

#10
zrhans

zrhans

    Newbie

  • Members
  • Pip
  • 3 posts
your codes are very helpfull.

#11
zrhans

zrhans

    Newbie

  • Members
  • Pip
  • 3 posts
Hi Jaan, I've got this error, can u help?
Fatal error: Call to undefined function imagecreatefromjpeg() in /home/hans/public_html/captcha/captcha.php on line 3

All the files are there (chmod 0755): index.php image.jpg text-font.otf and captcha.php

#12
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Hmm.. Looks like you have PHP version problem or something.. What PHP do you have?