w

특수문자, 스팸 문자 막기

요즘 게시판에 광고 올리는 놈들이 많아서 만든겁니다.

skin/board/basic/ajax.filter.php

안에 보면 문구를 봐서 die 시키는 구문이 있습니다. 여기에

$subject = strtolower($_POST['subject']);
$content = strtolower(strip_tags($_POST['content']));

밑에다가 아래처럼


$subject = strtolower($_POST['subject']); $content = strtolower(strip_tags($_POST['content'])); // 특수문자 제거 $msg=mb_convert_encoding($content,"EUC-KR","UTF-8"); $convMsg = mb_convert_encoding($msg, "UTF-8", "EUC-KR"); $pattern = '/[\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}\x{0000}-\x{00FF}]+/u'; preg_match_all($pattern,$convMsg,$match); $resultArr = mb_convert_encoding(implode('',$match[0]),"EUC-KR", "UTF-8"); if ($msg!=$resultArr) { $cont=""; die("{\"subject\":\"$subj\",\"content\":\"$cont\"}"); } // 한글만 남김 $msg=mb_convert_encoding($content,"EUC-KR","UTF-8"); $convMsg = mb_convert_encoding($msg, "UTF-8", "EUC-KR"); $pattern = '/[\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}]+/u'; preg_match_all($pattern,$convMsg,$match); $resultArr = mb_convert_encoding(implode('',$match[0]),"EUC-KR", "UTF-8"); $content = mb_convert_encoding($resultArr,"UTF-8","EUC-KR");

를 추가해주면 게시판에 특수문자를 입력 못하게 되고 "바.카.라..." 같이 특수문자가 중간에 들어간 한글도 걸러집니다.

첫번째 필터는 특수문자가 들어갔는지 검사하는 것이고
두번째 필터는 한글만 솎아 낸 후에 $content 에 대입시키는 것입니다.

|

댓글 4개

단점은 글에 특수문자를 입력하지 못합니다. 광고 때문에 짜증나는 경우 최후의 수단으로 고려해보세요.
좋은 팁이네요~~
감사합니다
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요. 나누면 즐거움이 커집니다.

+
제목 글쓴이 날짜 조회
14년 전 조회 1.4만
14년 전 조회 3,386
14년 전 조회 6,301
14년 전 조회 6,589
14년 전 조회 3,831
14년 전 조회 5,744
14년 전 조회 1.8만
14년 전 조회 7,930
14년 전 조회 5,237
14년 전 조회 5,570
14년 전 조회 5,836
14년 전 조회 2.3만
14년 전 조회 4,947
14년 전 조회 6,682
14년 전 조회 3,982
14년 전 조회 5,115
14년 전 조회 7,090
14년 전 조회 4,621
14년 전 조회 4,532
14년 전 조회 3,350
🐛 버그신고