Jump to content

Can you figure this CAPTCHA out?


codeboy89

Recommended Posts

Below is my CAPTCHA code, can anyone tell me why sometimes it displays the 6 numbers like it should, but other times it displays only 4 numbers? I cannot figure it out.

 

<?php
session_start();

$number = rand(1,999999); //generate a random integer
$_SESSION['number'] = $number; //store in session variable

$img_number = imagecreate(75,25);
$backcolor = imagecolorallocate($img_number,0xcc,0xcc,0xcc);
$textcolor = imagecolorallocate($img_number,255,255,255);

imagefill($img_number,0,0,$backcolor);

imagestring($img_number,3,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

Link to comment
https://forums.phpfreaks.com/topic/182414-can-you-figure-this-captcha-out/
Share on other sites

I made your captcha a little bit tougher:

 

<?php
$charset = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,Y,Z,1,2,3,4,5,6,7,8,9,!';
$char_array = explode(",",$charset);
$size_of_array = sizeof($char_array) - 1;

$num_chars_in_capthca = 6;
$captcha_string = "";
$i = 0;
while($i < $num_chars_in_capthca){
   $index = rand(0,$size_of_array);
   $captcha_string .= $char_array[$index];
   $i++;
}

$_SESSION['captcha_code'] = $captcha_string;

$img_number = imagecreate(75,25);
$backcolor = imagecolorallocate($img_number,0xcc,0xcc,0xcc);
$textcolor = imagecolorallocate($img_number,255,255,255);

imagefill($img_number,0,0,$backcolor);

imagestring($img_number,3,5,5,$captcha_string,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

I added lines this time: :)

 

<?php
$charset = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,Y,Z,1,2,3,4,5,6,7,8,9,!';
$char_array = explode(",",$charset);
$size_of_array = sizeof($char_array) - 1;

$num_chars_in_capthca = 6;
$captcha_string = "";
$i = 0;
while($i < $num_chars_in_capthca){
$index = rand(0,$size_of_array);
$captcha_string .= $char_array[$index];
$i++;
}

$_SESSION['captcha_code'] = $captcha_string;

$img_number = imagecreate(125,50);
$backcolor = imagecolorallocate($img_number,000,000,000);
$textcolor = imagecolorallocate($img_number,255,255,255);
$linecolor = imagecolorallocate($img_number,232,128,240);

imagefill($img_number,0,0,$backcolor);

imagestring($img_number,10,35,17,$captcha_string,$textcolor);

$num_lines = 3;
$i = 0;
while($i < $num_lines){
imageline ($img_number,rand(1,62),rand(1,25),rand(63,125),rand(26,50),$linecolor);
$i++;
}

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.