la roba che ho postato li già me la genera il codice per il captcha testuale :asd:
codice:
<?php
class TextualCaptcha
{
private $__font;
function __construct($Font)
{
// Try to open the font
$fp = @fopen($Font, 'rt');
// Check if the font was openend or not
if ($fp === false)
{
die('Unable to load font ' . $Font);
}
// Build font informations
$this->__font = new stdClass();
$this->__font->Height = trim(@stream_get_line($fp, 128, "\n"));
$this->__font->Characters = array();
// Check there was an error while reading width or height
if ($this->__font->Height == false)
{
die('Error while reading font informations');
}
// Try to read font characters
$characterIsCompleted = true;
while(feof($fp) === false)
{
// Read font character
$character = trim(@stream_get_line($fp, 128, "\n"));
// Check if character is valid
if ($character === false || strlen($character) != 1)
{
die('Unusable character or invalid length (max length 1)');
}
// Initialize character lines slot
$this->__font->Characters[$character] = array();
// Switch of character check
$characterIsCompleted = false;
// Start to read character lines
$characterLines = array();
// Loop for characters
for($line = 0; $line < $this->__font->Height; $line++)
{
$this->__font->Characters[$character][] =
($readCheck = trim(@stream_get_line($fp, 128, "\n")));
if ($readCheck === false)
{
die('An error occurred while reading character ' .
$character);
}
}
// Switch on character check
$characterIsCompleted = true;
}
// Chiude il file
fclose($fp);
// Check if charcter was readed all or not
if ($characterIsCompleted == false)
{
die('An error occurred while reading character ' . $character);
}
}
function GenerateCode($Length = 8)
{
$characters = array_keys($this->__font->Characters);
$code = '';
for($codeIndex = 0; $codeIndex < $Length; $codeIndex++)
{
mt_srand();
$code .= $characters[mt_rand(0, count($characters) - 1)];
}
return $code;
}
function GenerateCaptcha($Code, $CharacterToReplace = '*#@ç§', $CharacterSeparator = ' ', $SpaceCharacter = ' ', $ShowValuePossibility = 10)
{
$captchaText = '';
$codeLength = strlen($Code);
$characterToReplaceLength = strlen($CharacterToReplace);
// Initialize the show code value possibility per character code
$characterCodeShowValuePossibility = array();
for($codeIndex = 0; $codeIndex < $codeLength; $codeIndex++)
{
$characterCodeShowValuePossibility[$codeIndex] = $ShowValuePossibility;
}
// Loop font lines
for($codeLine = 0; $codeLine < $this->__font->Height; $codeLine++)
{
// Loop code characters
for($codeIndex = 0; $codeIndex < $codeLength; $codeIndex++)
{
// Get character line
$characterLine = $this->__font->Characters[$Code{$codeIndex}][$codeLine];
// Get character width
$characterLineWidth = strlen($characterLine);
// Loop character width
for($characterLineIndex = 0; $characterLineIndex < $characterLineWidth;
$characterLineIndex++)
{
// Check if must place a space or a character
if ($characterLine{$characterLineIndex} == '0')
{
// Put a space
$captchaText .= $SpaceCharacter;
}
else
{
// Check if must show the value of the current code or not
mt_srand();
if (mt_rand(0, 100) < $characterCodeShowValuePossibility[$codeIndex])
{
// Put the current character value
$captchaText .= $Code{$codeIndex};
// Reset possibility
$characterCodeShowValuePossibility[$codeIndex] = $ShowValuePossibility;
}
else
{
// Increment possibility
$characterCodeShowValuePossibility[$codeIndex]++;
// Put a casual character from CharacterToReplace
$captchaText .= $CharacterToReplace{mt_rand(0, $characterToReplaceLength - 1)};
}
}
}
if ($codeIndex != $codeLength - 1)
{
// Put character separator
$captchaText .= $CharacterSeparator;
}
}
// Put a new line
$captchaText .= "\r\n";
}
return $captchaText;
}
}
//$characterSet = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!"£$%&/()=\'ì?^è+ùé*§[]òàç°@#,.-;:________________________________________________________\\|';
$characterSet = '#@$§&#@$§&_';
$textualCaptcha = new TextualCaptcha('Fonts/StandardOnlyNumbers');
$code = $textualCaptcha->GenerateCode(6);
echo '<div style="font-family: Lucida Console; font-size: 4px; font-weight: bold;">' . str_replace("\r\n", "
\r\n", $textualCaptcha->GenerateCaptcha($code, $characterSet, '____', '_', -9999)) . '</div>';
?>
mentre il font (che va salvato dentro Fonts/StandardOnlyNumbers)
codice:
10
0
0000110000
0011111100
0110000110
0110000110
1100000011
1100000011
0110000110
0110000110
0011111100
0000110000
1
00011
01111
01111
11011
00011
00011
00011
00011
00011
00011
2
000111111
001100011
011000011
000001100
000001100
000110000
000110000
011000000
011000011
011111110