0.HTML文件结构
一.HTML文件
1.test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<!-- 将结果提交给/cgi-bin/test.cgi下 -->
<form action="/cgi-bin/test.cgi" method="post">
用户名: <input type="text" name="name">
密码: <input type="text" name="number">
<input type="submit" value="登录">
</form>
<a href="/cgi-bin/test.cgi"> 跳转到test.cgi </a>
</body>
</html>
2.choose.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>choose</title>
</head>
<body>
<!-- <H1>仓库1</H1> -->
<td height="62"><h1 align="center">仓库1</h1></td>
<h1 align="center" ><a href="/index.html"> 回到登陆界面 </a></h1>
</body>
</html>
登陆成功则会跳转到此页面
二.test.cgi文件
#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
int cgiMain()
{
char name[241] = {0};
char number[241] = {0};
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<HTML>\n");
fprintf(cgiOut,"<HEAD>\n");
fprintf(cgiOut, "<TITLE>My First CGI</TITLE>\n");
fprintf(cgiOut,"<meta charset='utf-8'>\n");
fprintf(cgiOut,"</HEAD>\n");
fprintf(cgiOut,"<BODY>\n");
fprintf(cgiOut, "<H1>Hello CGIC1</H1>\n");
cgiFormString("name",name,241); //获取名为name的数据
cgiFormString("number",number,241); //获取名为number的数据
fprintf(cgiOut,"<H2>name=%s</H2>\n",name);
fprintf(cgiOut,"<H2>number=%s</H2>\n",number);
fprintf(cgiOut, "<a href='/index.html'>本文本</a>\n\n");
//对比用户名和密码
if((!strcmp(name,"liuhai")) && (!strcmp(number,"123456")))
{
fprintf(cgiOut,"<p>登录成功</p>\n");
printf("<script language='javascript'>document.location = 'http://127.0.0.1/choose.html'</script>");
}
else
{
fprintf(cgiOut,"<p>登陆失败</p>\n");
}
fprintf(cgiOut, "</BODY>\n");
fprintf(cgiOut, "</HTML>\n");
return 0;
}