session_start();
$length = 6; // Captcha uzunligi
$captcha = generateRandomString($length); // Random matn generatsiya qilish
$_SESSION['captcha'] = $captcha; // Captcha matnini sesiyaga saqlash
// Captcha rasmini yaratish
$width = 200; // Rasim eni
$height = 80; // Rasim bo'yi
$image = imagecreatetruecolor($width, $height);
$bgColor = imagecolorallocate($image, 255, 255, 255); // Foydalanuvchi yuzi uchun rasm rangi
$textColor = imagecolorallocate($image, 0, 0, 0); // Matn rangi
imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
imagettftext($image, 40, 0, 50, 50, $textColor, 'fonts/arial.ttf', $captcha); // Font va matnning joylashuvi
header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);
// Random matn generatsiya qilish funksiyasi
function generateRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
?>
2. Matn va rasmlar kombinatsiyasini ishlatish:
```php
session_start();
$length = 6; // Captcha uzunligi
$captcha = generateRandomString($length); // Random matn generatsiya qilish
$_SESSION['captcha'] = $captcha; // Captcha matnini sesiyaga saqlash
// Rasimlarni yuklash
$bgImage = imagecreatefromjpeg('background.jpg'); // Orqa fon rasmi
$textColor = imagecolorallocate($bgImage, 255, 255, 255); // Matn rangi
Do'stlaringiz bilan baham: |