Programming/PHP2009/09/10 20:54


<?
function multiarray_search($arrayVet, $campo, $valor){
    while(isset($arrayVet[key($arrayVet)])){
        if($arrayVet[key($arrayVet)][$campo] == $valor){
            return key($arrayVet);
        }
        next($arrayVet);
    }
    return -1;
}

//퀴즈
$arr_quiz = array(
    0 => array(
        'day' => '2009-09-10',
        'ques' => '우주선에서 꽃을 키울 수 있다?',
        'ans' => 'Y'
    ),
    1 => array(
        'day' => '2009-09-14',
        'ques' => '아이젠은 천재다?',
        'ans' => 'Y'
    ),
    2 => array(
        'day' => '2009-09-17',
        'ques' => '누가 나를 미치게 했는가?',
        'ans' => 'Y'
    ),
    3 => array(
        'day' => '2009-09-20',
        'ques' => '1+1=2 는 정말인가?',
        'ans' => 'Y'
    ),
    4 => array(
        'day' => '2009-09-23',
        'ques' => '실물보다 사진이 나은가?',
        'ans' => 'Y'
    )
);

$keys = multiarray_search( $arr_quiz, 'day', '2009-09-11');
echo($keys);
?>

출력 : -1
즉 찾으면 key 를 반환하고, 찾치 못하면 -1을 반환

출처 : http://kr.php.net/manual/kr/function.array-search.php
erick dot xavier at gmail dot com
04-Jan-2007 09:57
저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 아이젠
Programming/PHP2009/07/08 12:21
fopen을 사용하다보면 의례 생각이 나야 할 것들이 생각이 안나 정리차원에서 올려본다.

매뉴얼 주소

A list of possible modes for fopen() using mode
mode Description
'r' Open for reading only; place the file pointer at the beginning of the file.
'r+' Open for reading and writing; place the file pointer at the beginning of the file.
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 아이젠
그누보드42009/07/05 14:14


그누보드가 버전이 업되면서 이 부분 처리가 미흡해 진건지 까먹고 처리 안한건지...
비회원으로 게시판 글 등록시 [정상적인 접근이 아닌것 같습니다.] 라는 메시지가 뜬다.
이게 스패머들의 자동등록을 방어하기위해 예전버전에 있었던 구문인데...
이게 최신버전으로 바뀌면서 계속 오류가 발생한다.

원 소스 116번째 줄에보면

// 자동등록방지 검사
//include_once ("./norobot_check.inc.php");

if (!$is_member) {
 if ($w=='' || $w=='r') {
     $key = get_session("captcha_keystring");
     if (!($key && $key == $_POST[wr_key])) {
  session_unregister("captcha_keystring");
  alert("정상적인 접근이 아닌것 같습니다.");
     }
 }
}

요런 부분이 있다.

이 부분을 아래 소스처럼 바꿔주면 된다.

// 자동등록방지 검사
//include_once ("./norobot_check.inc.php");

if($is_norobot) { #  이 부분 삽입
    if (!$is_member) {
        if ($w=='' || $w=='r') {
            $key = get_session("captcha_keystring");
            if (!($key && $key == $_POST[wr_key])) {
                session_unregister("captcha_keystring");
                alert("정상적인 접근이 아닌것 같습니다.");
            }
        }
    }
} # 이 부분 삽입

코멘트 등록시에도 이렇게 처리하면 될 것이다.(코멘트는 안써서;;;)

저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 아이젠