본문 바로가기

Technique/PHP

스팸글 자동등록 방지

반응형

auth_code.php

01.<?
02.session_start();
03.$_SESSION['key'] = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
04.header("Content-type: image/png");
05.$arry array('arial.ttf','cour.ttf','verdana.ttf','tahoma.ttf');
06.$wdth = 110; $hght = 50;
07.$img = imagecreate($wdth,$hght);
08.$clr_bckgrnd = imagecolorallocate($img,255,255,255);
09.$clr_frgrnd1 = imagecolorallocate($img,rand(10,255),rand(10,255),rand(10,255));
10.$clr_frgrnd2 = imagecolorallocate($img,rand(10,255),rand(10,255),rand(10,255));
11.$clr_frgrnd3 = imagecolorallocate($img,rand(10,255),rand(10,255),rand(10,255));
12.$clr_frgrnd4 = imagecolorallocate($img,rand(10,255),rand(10,255),rand(10,255));
13.imagefilledrectangle($img,0,0,$wdth,$hght,$clr_bckgrnd);
14.$clr_black = imagecolorallocate($img,200,200,200);
15.// 원그리기 시작위치y 시작위치x 크기 x 크기 y
16.for($i=0;$i<=$wdth;$i+=20){ // 가로 시작점
17.$f = rand(0,$hght);    // 세로 시작점
18.$b = rand(1,3);        // 원의 크기
19.ImageArc ($img$i$f$b$b, 0, 360, $clr_black); // 원 그리기
20.ImageFill ($img$i$f$clr_black); //그린원에 색채우기
21.}
22.$num = 5;
23.for ($i=$num$i<=$wdth$i+=10){  //가로 선
24.imageline($img,$i,0,$i,$hght,$clr_black);
25.}
26.for ($i=$num$i<=$hght+10; $i+=10){ //세로 선
27.imageline($img,0,$i,$wdth,$i,$clr_black);
28.}
29. 
30.imagettftext($img,rand(20,40),rand(0,10),5,rand(40,50),$clr_frgrnd1,$arry[rand(0,3)] substr($_SESSION['key'],0,1));
31.imagettftext($img,rand(20,40),rand(0,10),30,rand(40,50),$clr_frgrnd2,$arry[rand(0,3)],substr($_SESSION['key'],1,1));
32.imagettftext($img,rand(20,40),rand(0,10),55,rand(40,50),$clr_frgrnd3,$arry[rand(0,3)],substr($_SESSION['key'],2,1));
33.imagettftext($img,rand(20,40),rand(0,10),80,rand(40,50),$clr_frgrnd4,$arry[rand(0,3)],substr($_SESSION['key'],3,1));
34.imagepng($img);
35.imagedestroy($img);
36.?>

 

test.php
1.<form method="post" action="test_ok.php">
2.<img src="auth_code.php"  style="border:1px solid #dddddd"/><br>
3.<input type=text name="authcode" size="15" maxlength="20">
4.<input type="submit" value="전송">
5.</form>

 

test_ok.php
01.<?
02.session_start();
03.if(!$_SESSION['key'] OR $_POST['authcode']!=$_SESSION['key']) {
04.$_SESSION['key'] = rand(0,9).rand(0,9).rand(0,9).rand(0,9);
05.echo "스팸방지키가 잘못 입력되었습니다.";
06.}else{
07.echo "스팸방지키가 정상적으로 입력되었습니다.";
08.}
09.?>
10.<br>
11.<input type="button" value="뒤로" onclick="location.href='test.php'">


출처 ---------------------------------------------------------------------------


http://mopd.tistory.com/17


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

반응형

'Technique > PHP' 카테고리의 다른 글

자동방지글 등록 방지 모듈  (0) 2017.04.24