새 글 페이지 수정 질문드립니다.

새 글 페이지 수정 질문드립니다.

QA

새 글 페이지 수정 질문드립니다.

본문

현재 새 글 페이지에서 모든 회원의 작성글들이 출력이 되며

새 글 페이지 검색이나 URL마지막부분에 다른 회원의 아이디를 넣으면

해당 아이디의 새 글 들이 출력됩니다.

(Ex1 검색에 admin을 검색할시 admin의 글들이 출력됨)

(Ex2 비로그인상태에서 http://도메인/bbs/new.php?mb_id 여기서 마지막 부분에 =admin을 붙이면 admin의 글들이 출력됨)

 

위의 두가지 예시를 아래처럼 수정하고 싶습니다.

본인의 아이디(접속되어있는계정)의 게시물만 검색할 수 있게 하고싶습니다.

즉 타인의 게시물은 검색이 안되게끔요..

 

아무리 찾아봐도 제 실력으로는 무리인 것 같아 이렇게 또 고수분들께 도움을 요청합니다.ㅜㅜ

 

코드 같이 올려봅니다^^

 

 

<?php

include_once('./_common.php');

 

$g5['title'] = '새글';

include_once('./_head.php');

 

$sql_common = " from {$g5['board_new_table']} a, {$g5['board_table']} b, {$g5['group_table']} c where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = 1 ";

 

$gr_id = isset($_GET['gr_id']) ? substr(preg_replace('#[^a-z0-9_]#i', '', $_GET['gr_id']), 0, 10) : '';

if ($gr_id) {

    $sql_common .= " and b.gr_id = '$gr_id' ";

}

 

$view = isset($_GET['view']) ? $_GET['view'] : "";

 

if ($view == "w")

    $sql_common .= " and a.wr_id = a.wr_parent ";

else if ($view == "c")

    $sql_common .= " and a.wr_id <> a.wr_parent ";

else

    $view = '';

 

$mb_id = isset($_GET['mb_id']) ? ($_GET['mb_id']) : '';

$mb_id = substr(preg_replace('#[^a-z0-9_]#i', '', $mb_id), 0, 20);

 

if ($mb_id) {

    $sql_common .= " and a.mb_id = '{$mb_id}' ";

}

$sql_order = " order by a.bn_id desc ";

 

$sql = " select count(*) as cnt {$sql_common} ";

$row = sql_fetch($sql);

$total_count = $row['cnt'];

 

$rows = G5_IS_MOBILE ? $config['cf_mobile_page_rows'] : $config['cf_new_rows'];

$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산

if ($page < 1) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)

$from_record = ($page - 1) * $rows; // 시작 열을 구함

 

$group_select = '<label for="gr_id" class="sound_only">그룹</label><select name="gr_id" id="gr_id"><option value="">전체그룹';

$sql = " select gr_id, gr_subject from {$g5['group_table']} order by gr_id ";

$result = sql_query($sql);

for ($i=0; $row=sql_fetch_array($result); $i++) {

    $group_select .= "<option value=\"".$row['gr_id']."\">".$row['gr_subject'];

}

$group_select .= '</select>';

 

$list = array();

$sql = " select a.*, b.bo_subject, b.bo_mobile_subject, c.gr_subject, c.gr_id {$sql_common} {$sql_order} limit {$from_record}, {$rows} ";

$result = sql_query($sql);

for ($i=0; $row=sql_fetch_array($result); $i++) {

    $tmp_write_table = $g5['write_prefix'].$row['bo_table'];

 

    if ($row['wr_id'] == $row['wr_parent']) {

 

        // 원글

        $comment = "";

        $comment_link = "";

        $row2 = sql_fetch(" select * from {$tmp_write_table} where wr_id = '{$row['wr_id']}' ");

        $list[$i] = $row2;

 

        $name = get_sideview($row2['mb_id'], get_text(cut_str($row2['wr_name'], $config['cf_cut_name'])), $row2['wr_email'], $row2['wr_homepage']);

        // 당일인 경우 시간으로 표시함

        $datetime = substr($row2['wr_datetime'],0,10);

        $datetime2 = $row2['wr_datetime'];

        if ($datetime == G5_TIME_YMD) {

            $datetime2 = substr($datetime2,11,5);

        } else {

            $datetime2 = substr($datetime2,5,5);

        }

 

    } else {

 

        // 코멘트

        $comment = '[코] ';

        $comment_link = '#c_'.$row['wr_id'];

        $row2 = sql_fetch(" select * from {$tmp_write_table} where wr_id = '{$row['wr_parent']}' ");

        $row3 = sql_fetch(" select mb_id, wr_name, wr_email, wr_homepage, wr_datetime from {$tmp_write_table} where wr_id = '{$row['wr_id']}' ");

        $list[$i] = $row2;

        $list[$i]['wr_id'] = $row['wr_id'];

        $list[$i]['mb_id'] = $row3['mb_id'];

        $list[$i]['wr_name'] = $row3['wr_name'];

        $list[$i]['wr_email'] = $row3['wr_email'];

        $list[$i]['wr_homepage'] = $row3['wr_homepage'];

 

        $name = get_sideview($row3['mb_id'], get_text(cut_str($row3['wr_name'], $config['cf_cut_name'])), $row3['wr_email'], $row3['wr_homepage']);

        // 당일인 경우 시간으로 표시함

        $datetime = substr($row3['wr_datetime'],0,10);

        $datetime2 = $row3['wr_datetime'];

        if ($datetime == G5_TIME_YMD) {

            $datetime2 = substr($datetime2,11,5);

        } else {

            $datetime2 = substr($datetime2,5,5);

        }

 

    }

 

    $list[$i]['gr_id'] = $row['gr_id'];

    $list[$i]['bo_table'] = $row['bo_table'];

    $list[$i]['name'] = $name;

    $list[$i]['comment'] = $comment;

    $list[$i]['href'] = get_pretty_url($row['bo_table'], $row2['wr_id'], $comment_link);

    $list[$i]['datetime'] = $datetime;

    $list[$i]['datetime2'] = $datetime2;

 

    $list[$i]['gr_subject'] = $row['gr_subject'];

    $list[$i]['bo_subject'] = ((G5_IS_MOBILE && $row['bo_mobile_subject']) ? $row['bo_mobile_subject'] : $row['bo_subject']);

    $list[$i]['wr_subject'] = $row2['wr_subject'];

}

 

$write_pages = get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, "?gr_id=$gr_id&view=$view&mb_id=$mb_id&page=");

 

include_once($new_skin_path.'/new.skin.php');

 

include_once('./_tail.php');

?>

이 질문에 댓글 쓰기 :

답변 2

지금 올려주신 소스가 new.php에 보시면

$mb_id = isset($_GET['mb_id']) ? ($_GET['mb_id']) : '';

$mb_id = substr(preg_replace('#[^a-z0-9_]#i', '', $mb_id), 0, 20);

 

if ($mb_id) {

    $sql_common .= " and a.mb_id = '{$mb_id}' ";

}

있자나요 여기부분을 

if ($mb_id) {

   if ($mb_id == $member['mb_id']){

     $sql_common .= " and a.mb_id = '{$mb_id}' ";

   } else {

    alert('본인글만 검색 하실 수 있습니다.');

   }

}

 

if($mb_id)라고 있는 부분을 저렇게 수정을 답변드렸습니다.

즉 mb_id가 없을때는 전체글 기능 그대로 쓰고 mb_id로 검색했을때에는

타회원의 글을 검색하지 못하게 하는 형태입니다. 그러므로

도메인/skin/board/mypage/new.php?mb_id URL은 mb_id값이 없이 오는거니

전체글이 나오는게 맞습니다...

 

전체글이 기능을 아예 사용하지 않고 무조건 자기아이디글만 나오게 할꺼면

페이지 상단에 위에 소스는 무시하시고 new.php include 다음줄쯤에 

 

if (!$mb_id || $mb_id != $member['mb_id']){
    alert('본인글만검색가능합니다');
}

정도만 추가해주시면 될것 같습니다.

 

 

 

if ($mb_id) {

   if ($mb_id == $member['mb_id']){

     $sql_common .= " and a.mb_id = '{$mb_id}' ";

   } else {

    alert('본인글만 검색 하실 수 있습니다.);

   }

}

alert('본인글만 검색 하실 수 있습니다.); => alert('본인글만 검색 하실 수 있습니다.');
도메인/skin/board/mypage/new.php?mb_id 이렇게 주소창에 처보면
모든 회원들의 게시물들이 떠버려요ㅜㅜ

답변을 작성하시기 전에 로그인 해주세요.
전체 123,157
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT