테스트 사이트 - 개발 중인 베타 버전입니다

캡챠 UpGrade

· 10년 전 · 11606 · 5
수정하는 파일은 단 2개뿐이며, 글자 주위에 점들이 보이는 방식입니다.

******************************************************

먼저 아래의 파일 2개부터 백업부터 해 주세요... <-- ** 중요함 **

******************************************************

1) /plugin/kcaptcha/kcaptcha_config.php
2) /plugin/kcaptcha/kcaptcha.lib.php

******************************************************

첨부한 kcaptcha.lib.php 은 수정한 파일이며,
파일 덮어쓰지 마시고, 복사 붙여넣기 방식으로 해주세요.

******************************************************





[ 이제 수정 들어갑니다 ]----------------------


1) /plugin/kcaptcha/kcaptcha_config.php

의 제일 아래에 추가

#noise
//$white_noise_density=0; // no white noise
$white_noise_density=1/6;
//$black_noise_density=0; // no black noise
$black_noise_density=1/30;



2) /plugin/kcaptcha/kcaptcha.lib.php 의 파일 여셔서

class KCAPTCHA{
~~~
~~~
function setKeyString($str){
$this->keystring = $str;
}
}


을 아래의 내용으로 변경



class KCAPTCHA{

// generates keystring and image
function KCAPTCHA(){

require(dirname(__FILE__).'/kcaptcha_config.php');
$fonts=array();
$fontsdir_absolute=dirname(__FILE__).'/'.$fontsdir;
if ($handle = opendir($fontsdir_absolute)) {
while (false !== ($file = readdir($handle))) {
if (preg_match('/\.png$/i', $file)) {
$fonts[]=$fontsdir_absolute.'/'.$file;
}
}
closedir($handle);
}

$alphabet_length=strlen($alphabet);

do{
// generating random keystring
while(true){
$this->keystring='';
for($i=0;$i<$length;$i++){
$this->keystring.=$allowed_symbols{mt_rand(0,strlen($allowed_symbols)-1)};
}
if(!preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|ww/', $this->keystring)) break;
}

$font_file=$fonts[mt_rand(0, count($fonts)-1)];
$font=imagecreatefrompng($font_file);
imagealphablending($font, true);

$fontfile_width=imagesx($font);
$fontfile_height=imagesy($font)-1;

$font_metrics=array();
$symbol=0;
$reading_symbol=false;

// loading font
for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){
$transparent = (imagecolorat($font, $i, 0) >> 24) == 127;

if(!$reading_symbol && !$transparent){
$font_metrics[$alphabet{$symbol}]=array('start'=>$i);
$reading_symbol=true;
continue;
}

if($reading_symbol && $transparent){
$font_metrics[$alphabet{$symbol}]['end']=$i;
$reading_symbol=false;
$symbol++;
continue;
}
}

$img=imagecreatetruecolor($width, $height);
imagealphablending($img, true);
$white=imagecolorallocate($img, 255, 255, 255);
$black=imagecolorallocate($img, 0, 0, 0);

imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white);

// draw text
$x=1;
$odd=mt_rand(0,1);
if($odd==0) $odd=-1;
for($i=0;$i<$length;$i++){
$m=$font_metrics[$this->keystring{$i}];

$y=(($i%2)*$fluctuation_amplitude - $fluctuation_amplitude/2)*$odd
+ mt_rand(-round($fluctuation_amplitude/3), round($fluctuation_amplitude/3))
+ ($height-$fontfile_height)/2;

if($no_spaces){
$shift=0;
if($i>0){
$shift=10000;
for($sy=3;$sy<$fontfile_height-10;$sy+=1){
for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){
$rgb=imagecolorat($font, $sx, $sy);
$opacity=$rgb>>24;
if($opacity<127){
$left=$sx-$m['start']+$x;
$py=$sy+$y;
if($py>$height) break;
for($px=min($left,$width-1);$px>$left-200 && $px>=0;$px-=1){
$color=imagecolorat($img, $px, $py) & 0xff;
if($color+$opacity<170){ // 170 - threshold
if($shift>$left-$px){
$shift=$left-$px;
}
break;
}
}
break;
}
}
}
if($shift==10000){
$shift=mt_rand(4,6);
}

}
}else{
$shift=1;
}
imagecopy($img, $font, $x-$shift, $y, $m['start'], 1, $m['end']-$m['start'], $fontfile_height);
$x+=$m['end']-$m['start']-$shift;
}
}while($x>=$width-10); // while not fit in canvas

//noise
$white=imagecolorallocate($font, 255, 255, 255);
$black=imagecolorallocate($font, 0, 0, 0);
for($i=0;$i<(($height-30)*$x)*$white_noise_density;$i++){
imagesetpixel($img, mt_rand(0, $x-1), mt_rand(10, $height-15), $white);
}
for($i=0;$i<(($height-30)*$x)*$black_noise_density;$i++){
imagesetpixel($img, mt_rand(0, $x-1), mt_rand(10, $height-15), $black);
}


$center=$x/2;

// credits. To remove, see configuration file
$img2=imagecreatetruecolor($width, $height+($show_credits?12:0));
$foreground=imagecolorallocate($img2, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
$background=imagecolorallocate($img2, $background_color[0], $background_color[1], $background_color[2]);
imagefilledrectangle($img2, 0, 0, $width-1, $height-1, $background);
imagefilledrectangle($img2, 0, $height, $width-1, $height+12, $foreground);
$credits=empty($credits)?$_SERVER['HTTP_HOST']:$credits;
imagestring($img2, 2, $width/2-imagefontwidth(2)*strlen($credits)/2, $height-2, $credits, $background);

// periods
$rand1=mt_rand(750000,1200000)/10000000;
$rand2=mt_rand(750000,1200000)/10000000;
$rand3=mt_rand(750000,1200000)/10000000;
$rand4=mt_rand(750000,1200000)/10000000;
// phases
$rand5=mt_rand(0,31415926)/10000000;
$rand6=mt_rand(0,31415926)/10000000;
$rand7=mt_rand(0,31415926)/10000000;
$rand8=mt_rand(0,31415926)/10000000;
// amplitudes
$rand9=mt_rand(330,420)/110;
$rand10=mt_rand(330,450)/100;

//wave distortion

for($x=0;$x<$width;$x++){
for($y=0;$y<$height;$y++){
$sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1;
$sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10;

if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){
continue;
}else{
$color=imagecolorat($img, $sx, $sy) & 0xFF;
$color_x=imagecolorat($img, $sx+1, $sy) & 0xFF;
$color_y=imagecolorat($img, $sx, $sy+1) & 0xFF;
$color_xy=imagecolorat($img, $sx+1, $sy+1) & 0xFF;
}

if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){
continue;
}else if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){
$newred=$foreground_color[0];
$newgreen=$foreground_color[1];
$newblue=$foreground_color[2];
}else{
$frsx=$sx-floor($sx);
$frsy=$sy-floor($sy);
$frsx1=1-$frsx;
$frsy1=1-$frsy;

$newcolor=(
$color*$frsx1*$frsy1+
$color_x*$frsx*$frsy1+
$color_y*$frsx1*$frsy+
$color_xy*$frsx*$frsy);

if($newcolor>255) $newcolor=255;
$newcolor=$newcolor/255;
$newcolor0=1-$newcolor;

$newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0];
$newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1];
$newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2];
}

imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
}
}

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
if(function_exists("imagejpeg")){
header("Content-Type: image/jpeg");
imagejpeg($img2, null, $jpeg_quality);
}else if(function_exists("imagegif")){
header("Content-Type: image/gif");
imagegif($img2);
}else if(function_exists("imagepng")){
header("Content-Type: image/x-png");
imagepng($img2);
}
}

// returns keystring
function getKeyString(){
return $this->keystring;
}

function setKeyString($str){
$this->keystring = $str;
}
}



이제 실행 .... ^-^



------------------------------------------------------------------------------------

좀더 하고 싶으시다면

------------------------------------------------------------------------------------

1) 배경 변경 난수 ( /plugin/kcaptcha/kcaptcha_config.php )

/*
$foreground_color = array(0, 0, 0);
$background_color = array(255, 255, 255);
*/
$foreground_color = array(mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
$background_color = array(mt_rand(200,255), mt_rand(200,255), mt_rand(200,255));

------------------------------------------------------------------------------------

2) 주위의 점 갯수은 첫번째 환경설정 파일 수정 ( /plugin/kcaptcha/kcaptcha_config.php )
아래의 숫자을 크게하거나 작게 해보세요...

$white_noise_density=1/6;
$black_noise_density=1/30;

------------------------------------------------------------------------------------

3) 숫자 표현 갯수을 난수로 생성 ( /plugin/kcaptcha/kcaptcha_config.php )

// $length = 6;
$length = mt_rand(5,8);

------------------------------------------------------------------------------------

4) 그래도 또 광고가 올라온다면 /data/ 아래에 업로드하는 파일들을 먼저 뒤져 보세요.




댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 5개

[http://internationale.kr/data/file/info_gnuboard/1889776576_YUXCsGch_2014.12.09_01.png]

기본 적용...


[http://internationale.kr/data/file/info_gnuboard/1889776576_hfnMZE5U_2014.12.09_02.png]

추가 적용...
아래의 세가지 추가 적용을 하니... 바탕색이 들어가고 갯수도 랜덤으로...
문제는... 숫자를 읽어주는 소리 기능이 지맘대로 읽네요.
지금 확인해보니
class KCAPTCHA 안의 소스 일부분을 수정해줘야 되는것을 확인했어요.

이건 않할래요.....다른분이 하시는것으로... ^-^
숫자 난수로 하는 부분 적용하지 않고...

plugin/kcaptcha/kcaptcha.lib.php

상단의
function KCAPTCHA(){
이 부분을

function image(){
이렇게 원래 소스로 복구하고...

[code]// generating random keystring
while(true){
$this->keystring='';
for($i=0;$i<$length;$i++){
$this->keystring.=$allowed_symbols{mt_rand(0,strlen($allowed_symbols)-1)};
}
if(!preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|ww/', $this->keystring)) break;
}[/code]
이 부분 역시 원래대로 숨김 처리하니 정상 작동하네요.


난수 부분은... 원래 소스에
$length = mt_rand(5,6); # random 5 or 6
이런 부분이 있는데...
5개 일 때, 가끔 없는 숫자를 하나 더 읽어버리는 경우가 발생하더군요.
휴... 요것도 스팸글을 막지는 못하네요... 슬프다다

게시글 목록

번호 제목
2410
2401
2395
2387
2385
2377
2374
2372
2368
2367
2366
2364
2354
2353
2352
2349
2333
2329
2327
2304
2298
2297
2295
2288
2282
2279
2278
2276
2273
2268