Ana sayfa › Forumlar › PROGRAMLAMA › PHP › Php captcha sınıfı
- Bu konu 1 yanıt içerir, 2 izleyen vardır ve en son 12 yıl 8 ay önce Bahadir tarafından güncellenmiştir.
-
YazarYazılar
-
22 Nisan 2012: 19:34 #12716Gökhanİzleyici
width;
++$this->height;$this->im = imagecreatetruecolor($this->width,$this->height);
$bg = imagecolorallocate($this->im,$this->bgcolor[0],$this->bgcolor[1],$this->bgcolor[2]);
imagefill($this->im,0,0,$bg);$linecolors = imagecolorallocate($this->im,$this->linecolor[0],$this->linecolor[1],$this->linecolor[2]);
for($i = 0 ; $i <= $this->width ; $i = $i+10 )
{
imageline($this->im,0,$i,$this->width,$i,$linecolors);
imageline($this->im,$i,0,$i,$this->height,$linecolors);
}
}public function create()
{header(‘Content-Type:image/png’);
$this->write();
imagepng($this->im);
imagedestroy($this->im);
}public function chars()
{
$chr = ‘abcdefghijklmnoprstuxvyz1234567890ABCDEFGHIJKLMNOPRSTUWXYZ’;
for($i = 0 ; $i < $this->chars; $i++)
{
$key .= $chr[rand(0,strlen($chr)-1)];
}
if($this->case_sensivty)
{
$_SESSION[$this->session_name] = $key;
}
else
{
$_SESSION[$this->session_name] = strtolower($key);
}
return $key;
}private function write()
{
$fonts = $this->getfonts();
$chars = $this->chars();
$y_orgin = ($this->size > 35) ? 60 : 40;
$space = ($this->size > 35) ? 60 : 30;
if($fonts !== FALSE):
for($i = 0 ; $i < $this->chars ; $i++)
{
$angle = rand(-15,15);
$font = rand(0,count($fonts)-1);
$color = rand(0,count($this->colors)-1);
$color = explode(‘,’,$this->colors[$color]);
$color = imagecolorallocate($this->im,$color[0],$color[1],$color[2]);
imagettftext($this->im, $this->size ,$angle, 10 + ($i * $space) , $y_orgin , $color, $this->font_dir . DIRECTORY_SEPARATOR . $fonts[$font] ,$chars[$i]);
}
endif;
}private function getfonts()
{
$read = opendir($this->font_dir);
if($read)
{
while($list = readdir($read))
{
if($list != ‘.’ && $list != ‘..’ && preg_match(‘/(.ttf)$/’,$list))
{
$this->fonts[] = $list;
}
}
return $this->fonts;
}
else
{
return false;
}}
}?>
Örmek1:
start();
$captcha->create();
?>Örnek2:
bgcolor = array(112,138,144);
$captcha->linecolor = array(255,228,225);
$captcha->width = 250;
$captcha->height = 60;
$captcha->chars = 7;
$captcha->size = 30;
$captcha->session_name = ‘secret’;
$captcha->colors = array(‘49,79,79′,’25,25,112′,’34,139,34’);
$captcha->start();
$captcha->create();
?>İndex Örneği:
22 Nisan 2012: 19:37 #12720BahadirÜyeçok teşekkürler.
-
YazarYazılar
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.