-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcaptcha.php
More file actions
executable file
·36 lines (28 loc) · 919 Bytes
/
captcha.php
File metadata and controls
executable file
·36 lines (28 loc) · 919 Bytes
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
<?php
session_start();
header("Content-type: image/png");
// beri nama session dengan nama Captcha
$_SESSION["Captcha"] = "";
//tentukan ukuran gambar
$gbr = imagecreate(200, 50);
//warna background gambar
imagecolorallocate($gbr, 167, 218, 239);
$grey = imagecolorallocate($gbr, 128, 128, 128);
$black = imagecolorallocate($gbr, 0, 0,0);
// tentukan font
$font = "./assets/fonts/texb.ttf";
// membuat nomor acak dan ditampilkan pada gambar
for($i=0; $i<=7; $i++) {
// jumlah karakter
// $nomor = rand(0, 9);
$nomor = substr(hash("SHA256", rand()), 0, 1);
$_SESSION["Captcha"] .= $nomor;
$sudut = rand(-25, 25);
imagettftext($gbr, 20, $sudut, 8+15*$i, 25, $black, $font, $nomor);
// efek shadow
imagettftext ($gbr, 20, $sudut, 9+15*$i, 26, $grey, $font, $nomor);
}
//untuk membuat gambar
imagepng($gbr);
imagedestroy($gbr);
?>