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

간편하게 게시판 외부 스크립트에서 글 작성하기

안녕하세요?

외부 스크립트에서 글을 작성하실 때 보통 db에 직접 쿼리를 날리는 방법을 많이 사용하십니다.

 

그러나 이 방법은 스크립트가 글 작성 코드로 인해 지저분해질 뿐더러,

후킹 트리거에 정의한 기능을 사용하지 못하거나 각종 수정에 대응하지 못하는 등 단점이 분명히 존재합니다.

그래서 해당 글에서는 bbs/write_update.php 파일을 불러와서 글 작성을 할 수 있게 하는 방법을 소개하고자 합니다.

 

[code]

<?php

include dirname(__FILE__) . '/_common.php';

 

$g5driver = new gb5;

 

while (1)

{

    $obj = new stdClass;

    $obj->bo_table = 'free';

    $obj->name = '쓰니';

    $obj->subject = '제목';

    $obj->content = '내용';

    $writeresult = $g5driver->write($obj);

 

    $goodobj = new stdClass;

    $goodobj->bo_table = $writeresult['bo_table'];

    $goodobj->wr_id = $writeresult['wr_id'];

    $goodobj->wr_good = 69;

    $g5driver->updategood($goodobj);

 

    sleep(1);

}

 

class gb5

{

    public $write_update;

 

    function __construct()

    {

        $this->write_update = file_get_contents('bbs/write_update.php');

        $this->write_update = str_replace('<?php', '', $this->write_update);

        $this->write_update = str_replace('check_write_token($bo_table);', '$is_admin = true;', $this->write_update);

        $this->write_update = str_replace('$is_use_captcha =', '$xxxx =', $this->write_update);

        $this->write_update = str_replace('goto_url', 'echo', $this->write_update);        

    }

 

    function write($obj)

    {

        global $g5;

        $write_table = $g5['write_prefix'] . $obj->bo_table;

        $bo_table = $obj->bo_table;

        $_POST['wr_name'] = $obj->name;

        $_POST['wr_subject'] = $obj->subject;

        $_POST['wr_content'] = $obj->content;

        eval($this->write_update);

        return array('bo_table' => $bo_table, 'wr_id' => $wr_id);

    }

 

    function updategood($obj)

    {

        global $g5;

        sql_query(" update {$g5['write_prefix']}{$obj->bo_table} set wr_good = {$obj->wr_good} where wr_id = '{$obj->wr_id}' ");

    }

}

[/code]

 

해당 스크립트 실행 시 1초에 한번씩 free 게시판에 추천수 69개의 글이 작성되는 것을 보실 수 있습니다.

 

bbs/write_update.php를 불러와서 몇군데를 패치한 다음에 실행되도록 하였으며, 사용이 간편하도록 클래스화를 해보았습니다.

 

이 방법으로 댓글 작성 등의 여러가지 동작도 클래스 내부에 추가해 쉽게 구현 할 수 있을 것이라고 생각합니다.

댓글 작성

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

로그인하기

댓글 1개

수고하셨습니다~

게시판 목록

그누보드5 팁자료실

글쓰기
🐛 버그신고