forked from ABHRADEEP800/PHP-E_Commerce_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaptcha.php
40 lines (28 loc) · 761 Bytes
/
captcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
session_start();
// header for image
header("Content-type: image/png");
// random text
$text = substr(str_shuffle("23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"), 0, 5);
// store text in session
$_SESSION["captcha"] = $text;
// font
$font = "./monofont.ttf";
// image size
$width = 200;
$height = 50;
// create image
$image = imagecreatetruecolor($width, $height);
// background color
$color = imagecolorallocate($image, 176, 176, 176);
// text color
imagefilledrectangle($image, 0, 0, $width, $height, $color);
// random dots
$text_color = imagecolorallocate($image, 0, 0, 0);
// random lines
imagettftext($image, 25, 2, 60, 35, $text_color, $font, $text);
// output image
imagepng($image);
// clear memory
imagedestroy($image);
?>