Mini Shell
<?php
// captcha.php
session_start();
// Gera código: 6 caracteres sem confusões (sem 0/O e 1/I/l)
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
$len = 6;
$code = '';
for ($i = 0; $i < $len; $i++) {
$code .= $chars[random_int(0, strlen($chars) - 1)];
}
$_SESSION['captcha_code'] = $code;
// Tamanho da imagem
$w = 160; $h = 50;
// Cria canvas
$img = function_exists('imagecreatetruecolor') ? imagecreatetruecolor($w, $h) : imagecreate($w, $h);
// Cores
$bg = imagecolorallocate($img, 245, 248, 250);
$fg = imagecolorallocate($img, 20, 20, 20);
$noise1 = imagecolorallocate($img, 180, 180, 180);
$noise2 = imagecolorallocate($img, 210, 210, 210);
$border = imagecolorallocate($img, 160, 160, 160);
// Fundo
imagefilledrectangle($img, 0, 0, $w, $h, $bg);
// Ruído (linhas)
for ($i = 0; $i < 8; $i++) {
imageline($img, random_int(0,$w), random_int(0,$h), random_int(0,$w), random_int(0,$h), $noise1);
}
// Ruído (pontinhos)
for ($i = 0; $i < 300; $i++) {
imagesetpixel($img, random_int(0,$w-1), random_int(0,$h-1), $noise2);
}
// Texto com fonte interna do GD (funciona sem TTF)
$font = 5;
$fw = imagefontwidth($font);
$fh = imagefontheight($font);
$totalW = $fw * strlen($code);
$x = (int)(($w - $totalW) / 2);
$y = (int)(($h - $fh) / 2);
// Desenha char a char com leve jitter vertical
for ($i = 0; $i < strlen($code); $i++) {
$ch = $code[$i];
$yj = $y + random_int(-3, 3);
imagestring($img, $font, $x, $yj, $ch, $fg);
$x += $fw + random_int(0, 2);
}
// Borda
imagerectangle($img, 0, 0, $w - 1, $h - 1, $border);
// Output
header('Content-Type: image/png');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
imagepng($img);
imagedestroy($img);
Zerion Mini Shell 1.0