PHP Authentication Code Implementation
Include '. /lib/function.php ';
if (!isset ($_session)) {
??? Session_Start ();
??? Header (' cache-control:private ');
}
$width = 65;
$height = 20;
$image = Imagecreate ($width, $height);
$BG _color = imagecolorallocate ($image, 0x33, 0x66, 0xFF);
Imagefilledrectangle ($image, 0, 0, $width, $height, $BG _color);
$text = Random_text (5);
$font = 5;
$x = Imagesx ($image)/2-strlen ($text) * Imagefontwidth ($font)/2;
$y = Imagesy ($image)/2-imagefontheight ($font)/2;
$FG _color = imagecolorallocate ($image, 0xFF, 0xFF, 0xFF);
Imagestring ($image, $font, $x, $y, $text, $FG _color);
$_session[' captcha '] = $text;
Header (' content-type:image/png ');
Imagepng ($image);
Imagedestroy ($image);
?>
?
function Random_text ($count, $rm _similar = False)
{
??? $chars = Array_flip (array_merge (range (0, 9), Range (' A ', ' Z '));
??? if ($rm _similar) {
??????? unset ($chars [0], $chars [1], $chars [2], $chars [5], $chars [8], $chars [' B '], $chars [' I '],
??????????? $chars [' O '], $chars [' Q '], $chars [' S '], $chars [' U '], $chars [' V '], $chars [' Z ']);
??? }
??? for ($i = 0, $text = "; $i < $count; $i + +) {
??????? $text. = Array_rand ($chars);
??? }
??? return $text;
}
?>