zend_module_entry의 RSHUTDOWN 다음 위치에 지정하면 됨.

주의해야 할 점은 phpinfo()가 HTML 버전으로 나갈 것인가, plaintext 로 나갈 것인가 체크해야 한다는 것.
직접 구분하는 방법은 sapi_module.phpinfo_as_text 를 체크하는 것.
그냥 따로 막 태그를 꾸며서 출력하지 않고 API를 사용하면 알아서 변환해줌..


아래는 phpinfo()에 출력하기 위해 필요한 함수들이며, ext/standard/info.h 를 include 해야 함.



/*
PHP의 htmlentites() 함수와 같다.
이 함수에서 리턴된 문자열은 emalloc()으로 할당된 메모리여야 하고,
다 쓰고 나서는 efree()로 해제해야 한다.
*/

char *php_info_html_esc(char *str TSRMLS_DC)

/*
제목과 테이블의 시작태그를 출력한다.
아래와 같은 html 태그를 출력.
<h2><a name="module_$EXT_NAME">$EXT_NAME</a></h2>
<table border="0" cellpadding="3" width="600">
*/

void php_info_print_table_start(void)

/*
테이블 닫기 태그를 출력.
</table><br/>
*/

void php_info_print_table_end(void)

/*
테이블 제목 출력
<tr class="h"><th>$ARG2</th><th>$ARG3</th></tr>
*/

void php_info_print_table_header(int cols, ...)

/*
테이블 제목을 colspan을 먹여서 출력
<tr class="h"><th colspan="$ARG1">$ARG2</th></tr>
*/

void php_info_print_table_colspan_header(int cols, char *header)

/*
테이블의 열을 출력
<tr><td class="e">$ARG2</td><td class="v">$ARG3</td></tr>
*/

void php_info_print_table_row(int cols, ...)

/*
테이블의 열을 출력하되 <td>의 class를 지정할 수 있다.
<tr><td class="e">$ARG3</td><td class="$ARG2">$ARG4</td></tr>
*/

void php_info_print_table_row_ex(int cols, char *class, ...)

/*
테이블의 시작을 출력한다.
php_info_print_table_start()와 다른 점은 제목이나 기타 등등 다 떼고 테이블 시작만 출력한다는 것.
flag가 0이 아니면 class로 h가 사용되고 0이면 v가 사용된다.
<table border="0" cellpadding="3" width="600">
<tr class="v"><td>
*/

void php_info_print_box_start(int flag)

/*
테이블을 닫는다.
</td></tr>
</table><br />
*/

void php_info_print_box_end()

/*
<hr />을 출력한다.
plaintext일 경우 31개의 ____ 를 출력한다.
*/

void php_info_print_hr(void)









아래는 phpinfo를 다루는 그냥 단순 예제.



stdafx.h

#pragma once

#include "zend_config.w32.h"
#include "php.h"
#include "php_myext.h"
#include "ext/standard/info.h"




php_myext.h

#ifndef PHP_MYEXT_H
#define PHP_MYEXT_H 1

#define PHP_MYEXT_VERSION "1.0"
#define PHP_MYEXT_EXTNAME "myext"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

extern "C" {
    #ifdef ZTS
    #include "TSRM.h"
    #endif
}

PHP_MINFO_FUNCTION(myext);

extern zend_module_entry myext_module_entry;
#define phpext_myext_ptr &myext_module_entry;

#endif





myext.cpp

#include "stdafx.h"

startic function_entry myext_functions[] = {
    {NULL, NUlL, NULL}
};

zend_module_entry myext_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
    STANDARD_MODULE_HEADER,
#endif
    PHP_MYEXT_EXTNAME,
    myext_functions,
    NULL,
    NULL,
    NULL,
    NULL,
    PHP_MINFO(myext),
#if ZEND_MODULE_API_NO >= 20010901
    PHP_MYEXT_VERSION,
#endif
    STANDARD_MODULE_PROPERTIES
};

extern "C" {
    ZEND_GET_MODULE(myext)
}

PHP_MINFO_FUNCTION(myext)
{
    php_info_print_table_start();
    php_info_print_table_header(2, "Title", "Description");
    php_info_print_table_row(2, "Title 1", "Desc 1");
    php_info_print_table_row_ex(2, "my_class_name", "Title 2", "Desc 2");
    php_info_print_table_end();

    if (sapi_module.phpinfo_as_text) {
        // plain text
    }
    else {
        // HTML
    }
}









Posted by bloodguy
,