'조회수 중복 방지'에 해당되는 글 1건

728x90

게시판 기능을 구현하고 있는데, 코딩 구현보다 Layout 기능 익히는 게 더 힘들어서 적어둔다.

기능 구현이 끝나면 수정해야 할 부분(보안 문제 고려사항)

error_reporting(E_ALL);
ini_set("display_errors", 1);


error_reporting(0); 로 변경해야 한다.

 

<?php

// 파일명 : bbsView.php
error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once 'path.php';// root 폴더를 기준으로 상대적인 경로 자동 구하기
require_once $g['path_root'].'sessionChk.php';
require_once $g['path_root'].'deviceChk.php';
if($mtype == 3){
    require_once $g['path_root'].'ipFiltering.php'; // PC접속은 IP 접속 허용이 된 경우에만 접속 가능
}
require_once $g['path_config'].'config.php';
require_once $g['path_config'].'dbconnect.php';
require_once $g['path_class'].'dbDataClass.php';
require_once $g['path_class'].'bbsClass.php';
$c = new bbsClass();
$d = new DBDataClass();

$bid = isset($_GET['bid']) ? $_GET['bid']: '';
$curPage = isset($_GET['p']) ? $_GET['p'] : 1;

$R = $d->getDbData('bbs_data', 'uid="'.$_GET['uid'].'"', '*');
$html = ($R['html'] == 1) ? 'HTML' : 'TEXT';

 

// 쿠키를 이용한 조회수 중복 방지
if(!empty($R['uid']) && empty($_COOKIE['bbs_data_'.$R['uid']])) {
    if(strcmp($_SESSION['userID'],$R['userID']) !== 0){ // 등록자 본인이 아니면
        $d->getDbUpdate('bbs_data','hit=hit+1','uid='.$R['uid']);
        setcookie('bbs_data_'.$R['uid'], TRUE, time() + (60 * 60 * 24), '/');
    }
}

?>
<table class="table table-bordered table-hover table-sm" cellspacing="0" width="100%">
    <tr>
        <td style="width:70px;">제목</td>
        <td class="text-left"><?php echo $R['subject']?></td>
    </tr>
    <tr>
        <td>내용</td>
        <td class="text-left"><?php echo $c->getContents($R['content'],$html);?></td>
    </tr>
</table>

<?php include_once $g['path_bbs'].'bbsComment.php';?>

 

<div class="table-responsive text-nowrap">
    <div class="float-left info">
        <button class="btn btn-md btn-outline-default m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="BBSHome">목록</button>
    </div>
    <div class="float-right info">
        <?php if($R['userID'] == $_SESSION['userID'] || (isset($_SESSION['authID']) && $_SESSION['authID']==1 )):?>
        <a href="bbsWrite.php" class="btn btn-md btn-outline-default m-0 px-3 py-2 z-depth-0 waves-effect" id="bbsModify" data-id="<?=$R['uid'];?>" curPage="<?=$curPage;?>">수정</a>
        <button class="btn btn-md btn-outline-default m-0 px-3 py-2 z-depth-0 waves-effect" type="button" id="bbsDelete" data-id="<?=$R['uid'];?>" curPage="<?=$curPage;?>">삭제</button>
        <?php endif;?>
    </div>
</div> 

 

bbsComment.php ==> 댓글 달기 및 댓글 보기

<?php

// 파일명 : bbsComment.php

error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once 'path.php';// root 폴더를 기준으로 상대적인 경로 자동 구하기
require_once $g['path_root'].'sessionChk.php';
require_once $g['path_root'].'deviceChk.php';
if($mtype == 3){
    require_once $g['path_root'].'ipFiltering.php';
}
require_once $g['path_config'].'config.php';
require_once $g['path_config'].'dbconnect.php';
require_once $g['path_class'].'dbDataClass.php';
$d = new DBDataClass();

?>

<div class="form-group">
    <form name="commentForm" class="form-inline">
        <input type="hidden" name="mode" value="new" />
        <input type="hidden" name="parentid" value="<?php echo $_GET['uid'];?>" />
        <input type="hidden" name="userID" value="<?php echo $_SESSION['userID'];?>" />
        <input type="hidden" name="userNM" value="<?php echo $_SESSION['userNM'];?>" />
        <input type="hidden" name="p" value="<?=$curPage;?>" />

        <div class="input-group mb-3" style="width:100%;">
          <input type="text" name="comment" class="form-control" placeholder="댓글을 입력하세요" aria-label="comment"
            aria-describedby="comment_form">
          <div class="input-group-append">
            <button type="button" class="btn btn-md btn-outline-default m-0 px-3 py-2 z-depth-0 waves-effect" id="comment_form">댓글</button>
          </div>
        </div>

    </form>
</div>

<div class="table-responsive text-nowrap">
<table class="table table-hover table-sm" cellspacing="0" width="100%">
    <tbody>
    <?php $COMM = $d->getDbArray('bbs_comment','parentid="'.$_GET['uid'].'"','*','uid DESC',0,1);?>
    <?php while($C = mysqli_fetch_array($COMM)):?>
        <tr id="<?php echo $C['uid'];?>">
            <td class="text-left"><?php echo $C['userID'];?></td>
            <td class="text-left"><?php echo $C['comment'];?></td>
            <td><?php echo substr($C['d_regis'],0,8);?></td>
            <td>
            <button class="btn btn-md m-0 z-depth-0 comment_del" type="button" title='삭제'>&times;</button>
            </td>
        </tr>
    <?php endwhile;?>
    </tbody>
</table>
</div>

<?php
// 파일명 : bbsCommentChk.php
if(!isset($_SESSION)){
    session_start();
}
//echo '<pre>';print_r($_POST);echo '</pre>';
//exit;
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST"){
    @extract($_POST);
    require_once 'path.php';// root 폴더를 기준으로 상대경로 자동 구하기
    require_once $g['path_config'].'dbconnect.php';
    require_once $g['path_class'].'dbDataClass.php';
    $d = new DBDataClass(); // AES_Decode()

    $comment = trim($comment);
    date_default_timezone_set('Asia/Seoul');

    if($mode == 'new'){
        $d_regis = date('YmdHis');
        $access_ip=$_SERVER['REMOTE_ADDR'];
        $QKEY = "parentid,comment,d_regis,userID,userNM,ip";
        $QVAL = "'$parentid','$comment','$d_regis','$userID','$userNM','$access_ip'";
        $d->getDbInsert('bbs_comment',$QKEY,$QVAL);
        echo 1;
    } else {
        // 등록자 여부 체크
        $R = $d->getUidData('bbs_comment',$uid);
        if($R['userID'] == $_SESSION['userID']){
            $QSET="comment='".$comment."'";
            $QVAL="uid='".$uid."'";

            $d->getDbUpdate('bbs_data',$QSET,$QVAL);
            echo 2;
        } else {
            echo -2;
        }
    }
} else {
    echo -1;
}
?>

<?php
// 파일명 : bbsCommentDelete.php
require_once 'path.php';// root 폴더를 기준으로 상대적인 경로 자동 구하기
require_once $g['path_root'].'sessionChk.php';
require_once $g['path_root'].'deviceChk.php';
if($mtype == 3){
    require_once $g['path_root'].'ipFiltering.php';
}
require_once $g['path_config'].'config.php';
require_once $g['path_config'].'dbconnect.php';
require_once $g['path_class'].'dbDataClass.php';
$d = new DBDataClass;

if(!isset($_GET['idx']) || empty($_GET['idx'])){
    $rs=0;
} else {
    // 등록자 여부 체크
    $R = $d->getUidData('bbs_comment',$_GET['idx']);
    if($R['userID'] == $_SESSION['userID'] || (isset($_SESSION['authID']) && ($_SESSION['authID']==1 || $_SESSION['authID']==2))){
        // 등록자 또는 관리자(관리자, 최고관리자) 인 경우에는 삭제 가능
        $rs=$d->getDbDelete('bbs_comment', 'uid='.$_GET['idx'].'');
    } else {
        $rs = -2;
    }
}
echo $rs;
?>

 

jQuery 처리 부분은 https://link2me.tistory.com/1665 를 참조하면 된다.

 

블로그 이미지

Link2Me

,