本文介紹使用apache實現C語言寫的cgi程序。
必要條件,安裝apache。
首先建立C程序,這裏就不多介紹。參照前面的文章或者其它的參考書籍。
建立文件hello.c,內容如下:
#include <stdio.h>
int main()
{
printf(“Content-type:text/html\n\n”);
printf(“<html>”);
printf(“<head><title>welcome to c cgi.</title></head><body>”);
printf(“你好:世界<br/>”);
printf(“</body></html>”);
}
然後配置 apache 配置文件 httpd.conf。在配製文件中找到
AddHandler cgi-script .cgi 在這一行後面加上 .exe,並且去掉前邊的#
最後在瀏覽器中輸入 http://localhost/cgi-bin/hello.exe,回車。
在瀏覽器中將顯示:你好:世界。