ubuntu 下CGI c语言 获取form表单的数据
时间:2014-05-06 22:57:48
收藏:0
阅读:592
这次 主要使用CGI c语言 获取form表单的数据
1 login.c
aries@ubuntu:/usr/lib/cgi-bin$ cat login.c
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
int main(){
int i,len=0;
char poststr[100];
char m[10],n[10];
char *req_method;
printf("Content-type:text/html\n\n");
printf("<meta charset=\"utf-8\">");
printf("<title>检测页面</title>");
printf("<h1>将post过来的和数据库中的信息进行比对即可</h11>");
req_method = getenv("REQUEST_METHOD");
if (!strcmp(req_method, "POST"))
len=atoi(getenv("CONTENT_LENGTH"));
printf("传过来的字符数: %d \n",len);
fgets(poststr,len+1,stdin);
printf("显示post过来的数据:<br /><br />");
printf("%s\n",&poststr);
return 0;
}
aries@ubuntu:/usr/lib/cgi-bin$ sudo gcc -o login.cgi login.c
aries@ubuntu:/usr/lib/cgi-bin$ ls
login.c login.cgi
2 login.html
aries@ubuntu:/var/www$ cat login.html
<html>
<head><title>用户登陆验证</title></head>
<body>
<form name="form1" action="/cgi-bin/output.cgi" method="POST">
<table align="center">
<tr><td align="center" colspan="2"></td></tr>
<tr>
<td align="right">用户名</td>
<td><input type="text" name="Username"></td>
</tr>
<tr>
<td align="right">密 码</td>
<td><input type="password" name="Password"></td>
</tr>
<tr>
<td><input type="submit" value="登 录"></td>
<td><input type="reset" value="取 消"></td>
</tr>
</table>
</form>
</body>
</html>
3 http://localhost/login.html
4 点击登录
获取成功!
评论(0)