-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcaptcha.php
More file actions
45 lines (42 loc) · 1.22 KB
/
captcha.php
File metadata and controls
45 lines (42 loc) · 1.22 KB
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
41
42
43
44
45
<?php
session_start();
/**
* PHP CAPTCHA CLASS
* WRITTEB BY : SEMICOLON
* AHMED MAHER HALIMA
* https://www.facebook.com/ahmedmaherhalima
**/
/**
*
*/
class Captcha
{
public $img;
public $txtCol;
public $fontSize = 40; // here you can change your captcha font size
public $imageWidth = 80; // here you can change your captcha image width
public $imageHeight = 20; // here you can change your captcha image height
public $string;
public function createImg(){
$this->img = imagecreate($this->imageWidth, $this->imageHeight);
imagecolorallocate($this->img, 255, 255, 255);
$this->txtCol = imagecolorallocate($this->img, 0, 0, 0);
//draw lines on image
for($i = 0; $i <= 30; $i++ ){
$x1 = rand(1,100);
$y1 = rand(1,100);
$x2 = rand(1,100);
$y2 = rand(1,100);
imageline($this->img, $x1, $y1, $x2, $y2,$this->txtCol);
}
// add captcha string to image
$this->string = md5(microtime());
$this->string = substr($this->string, 0 , 6);
$_SESSION['secret'] = $this->string;
imagestring($this->img, $this->fontSize, 0, 0, $this->string, $this->txtCol);
imagepng($this->img);
} // end createImg function
}
$captcha = new Captcha();
$captcha->createImg();
?>