2010-11-28 6 views

답변

17

물론입니다.

#include <stdio.h> 

int main(int argc, char *argv[]]) 
{ 
    printf("Content-type: text/plain\n\n"); 
    printf("Hello, world!\n") 
} 
+2

cgi-app.cgi 당신을 위해, 간단하게이수록. :) – casablanca

+0

어떻게 브라우저 (fire fox)로이 CGI 코드를 실행합니까? – Amra

+2

당신이 사용하고있는 서버와 컴파일러의 특성에 따라,'\ n \ '대신에'\ r \ n' 시퀀스를 사용해야 할 것입니다. 왜냐하면 HTTP는 개행 문자가 나오고 개행 문자가 오는 것을 기대하기 때문입니다. 대부분의 브라우저는 어떤 경우에도 고독한 개행을 허용합니다. – SingleNegationElimination

3

에바, 당신은 웹 형식의 실행을 지원하기 위해 매우 유용한 라이브러리가 (브라우저, 웹 서버 등에서 실행 CGI - bin에) 이그나시오의 대답의 기초를 이해하면. 여기

, 나는 C에서 내 CGI에 사용되는 라이브러리 잘 작동, 당신이 일에 저장합니다
이 (cgihtml은 C 작성된 CGI와 HTML 루틴의 집합을)
http://eekim.com/software/cgihtml/index.html

추가 할 수있는 HTML
http://www.algonet.se/~thunberg/template2doc/

경량 웹 서버 :
http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servers

많은 양의 데이터를 표시하기위한 템플릿개

과 더 많은 자원 :
http://cgi.resourceindex.com/Programs_and_Scripts/C_and_C++/Libraries_and_Classes/

http://en.wikipedia.org/wiki/Common_Gateway_Interface

0

는 C 웹 애플리케이션을위한 오픈 소스 CGI 및 FastCGI를 라이브러리를 kcgi

kcgi을 살펴있다 되세요.

#include <stdio.h> 

int main() 
{ 
    printf("content-type: text/plain\n\n"); 
    printf("Hello, world!"); 

    return 0; 
} 

내가 컴파일 된 파일이 cgi-app.cgi 있다고 가정 : 그것은 최소한의 안전하고

#include <sys/types.h> /* size_t, ssize_t */ 
#include <stdarg.h> /* va_list */ 
#include <stddef.h> /* NULL */ 
#include <stdint.h> /* int64_t */ 
#include <stdlib.h> /* EXIT_SUCCESS, etc. */ 
#include <kcgi.h> 

int main(void) { 
    struct kreq r; 
    const char *page = "index"; 
    if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0)) 
    return(EXIT_FAILURE); 
    khttp_head(&r, kresps[KRESP_STATUS], "%s", khttps[KHTTP_200]); 
    khttp_head(&r, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME__MAX == r.mime ? 
     KMIME_APP_OCTET_STREAM : r.mime]); 
    khttp_body(&r); 
    khttp_puts(&r, "Hello, world!"); 
    khttp_free(&r); 
    return(EXIT_SUCCESS); 
} 
1

실행 파일에이 간단한 소스 코드를 컴파일 감사입니다

gcc cgi-src.c -o cgi-app.cgi 

httpd을 y로 실행하면 우리의 서버 소프트웨어, 당신은 당신의 디렉토리에 cgi-app.cgi를 넣을 수 있습니다 :

  1. cgi-bin을 : 대부분의 경우에 CGI를 실행할 수 있습니다.
  2. htdocs : 당신의 .htaccess 파일에 두 줄을 추가 :
            
 
Options +ExecCGI AddHandler cgi-script .cgi

설정하지 잊지 마십시오 적합한 execute 권한을 .htaccess