使用CGI c语言 获取form表单的数据

来源:互联网 发布:软件介绍ppt模板 编辑:程序博客网 时间:2024/04/30 00:50

login.c

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. aries@ubuntu:/usr/lib/cgi-bin$ cat login.c  
  2. #include<stdio.h>    
  3. #include<stdlib.h>    
  4. #include <string.h>    
  5. int main(){    
  6.     int i,len=0;    
  7.     char poststr[100];    
  8.     char m[10],n[10];    
  9.     char *req_method;       
  10.     printf("Content-type:text/html\n\n");    
  11.     printf("<meta charset=\"utf-8\">");    
  12.     printf("<title>检测页面</title>");    
  13.     printf("<h1>将post过来的和数据库中的信息进行比对即可</h11>");    
  14.     req_method = getenv("REQUEST_METHOD");     
  15.      if (!strcmp(req_method, "POST"))    
  16.        len=atoi(getenv("CONTENT_LENGTH"));    
  17.     
  18.     printf("传过来的字符数: %d \n",len);    
  19.         fgets(poststr,len+1,stdin);    
  20.     printf("显示post过来的数据:<br /><br />");    
  21.     printf("%s\n",&poststr);    
  22.     return 0;    
  23. }    

aries@ubuntu:/usr/lib/cgi-bin$ sudo gcc -o login.cgi login.c

aries@ubuntu:/usr/lib/cgi-bin$ ls
login.c  login.cgi

0 0
原创粉丝点击