准备工作:新建文件夹,放入cgic.c cgic.h login.c和Makefile(后面新建),登录名为111,密码为222
效果图为:
login.html 放到www目录下
<html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>login</title> </head> <body> <form action="cgi-bin/demo/login.cgi" method="POST"> <div align=left> <font>账户登陆</font><input type="text" name="name" /> </div> <div align=left> <font>账户密码</font><input type="text" name="number" /></div> <div align=left><input type="submit" value="login" /></div> </form> </body> </html>
login.c,,,,,程序乱码了,需要改下乱码部分为中文
#include <stdio.h> #include "cgic.h" #include <string.h> #include <stdlib.h> char rightname[]="111",rightnumber[]="222"; int i=0,flag=0,heart=30,breathe=8,blood=160,bloodox=82;//100; int cgiMain() { char name[241]; char stop[241]; char tijiao[241]; char number[241]; char hometitle[]="嵌入式智能医疗监测系统",bodywarn[]="发烧状态",breathewarn[]="呼吸异常",heartwarn[]="心率异常",bloodoxwarn[]="血氧异常",bloodwarn[]="血压过高",blank[]=" "; char xianshi[]=" "; float bodytemp=37.6;//36.3; static int comenum=0; blood+=1; // int lenlen; cgiHeaderContentType("text/html"); fprintf(cgiOut, "<HTML><HEAD> "); fprintf(cgiOut, "<TITLE>CGIC</TITLE></HEAD> "); fprintf(cgiOut, "<BODY>"); cgiFormString("name", name, 241); cgiFormString("number", number, 241); cgiFormString("tijiao", tijiao, 241); cgiFormString("stop", stop, 241); // lenlen=strlen(name); // printf("%d ",lenlen); for(i=0;i<3;i++) { if(name[i]==rightname[i]&&number[i]==rightnumber[i]) flag+=1; } // fprintf(cgiOut, "<h1>%s</h1>",name); // printf("printf is here");printf("printf is here");printf("printf is here "); if(flag==3) { fprintf(cgiOut, "<div align=left ><font color=blue size=7 > %s</font> </div> ",hometitle); fprintf(cgiOut, "<br/><br/>"); printf("<div align=left ><font color=black size=5 >1ºÅ´²</font> </div> "); if(blood<160) for(i=0;i<8;i++) xianshi[i]=blank[i]; else for(i=0;i<8;i++) xianshi[i]=bloodwarn[i]; printf( "<div align=left ><font align=center color=purple size=4 >Ѫѹ£º</font> <font> <u>%d</u> mmHg <font color=red > %s</font></font> </div>",blood,xianshi); if(bodytemp*10<=373) for(i=0;i<8;i++) xianshi[i]=blank[i]; else for(i=0;i<8;i++) xianshi[i]=bodywarn[i]; printf( "<div align=left ><font color=purple size=4 >ÌåΣº</font> <font> <u>%2.1f</u>ÉãÊ϶È<font color=red > %s</font></font> </div> ",bodytemp,xianshi); if(heart>=60) for(i=0;i<8;i++) xianshi[i]=blank[i]; else for(i=0;i<8;i++) xianshi[i]=heartwarn[i]; printf( "<div align=left ><font color=purple size=4 >ÐÄÂÊ£º</font>ÿ·ÖÖÓ <font> <u>%d</u>´Î<font color=red > %s</font></font> </div> ",heart,xianshi); if(breathe>=10) for(i=0;i<8;i++) xianshi[i]=blank[i]; else for(i=0;i<8;i++) xianshi[i]=breathewarn[i]; printf( "<div align=left ><font color=purple size=4 >ºôÎüÂÊ£º</font>ÿ·ÖÖÓ <font> <u>%d</u>´Î<font color=red > %s</font></font> </div> ",breathe,xianshi); if(bloodox>=90) for(i=0;i<8;i++) xianshi[i]=blank[i]; else for(i=0;i<8;i++) xianshi[i]=bloodoxwarn[i]; printf( "<div align=left ><font color=purple size=4 >ѪÑõ±¥ºÍ¶È£º</font> <font> <u>%d </u>%%<font color=red > %s</font></font> </div> ",bloodox,xianshi); } //chaolianjie refresh /* printf( " <a href=http://192.168.1.103/cgi-bin/demo/login.cgi title=login <div align=left><input type='submit' value='comein' /></div> </a> ");*/ tijiao[0]='1'; tijiao[1]='3'; tijiao[2]='3'; printf("<form action='login.cgi' method='POST'> "); printf("<div align=left> <input type=hidden name=tijiao /> </div> <div align=left> <input type=hidden name=name value=111 /></div> <div align=left> <input type=hidden name=number value=222 /></div>"); printf("<div align=left><input type=submit value=login /></div> </form> "); //the int 1 in ASCII is 49 if(tijiao[0]=='1') {printf("%c ",tijiao[0]); printf("%c ",tijiao[1]); printf("%c ",tijiao[2]); blood+=1; printf("blood : %d ",blood); if(blood==1000)blood=0; } printf("%d ",tijiao[1]); printf("blood : %d ",blood); comenum++; printf("comenum : %d ",comenum); /* printf("<form action='login.cgi' method='POST'> "); printf("<div align=left> <input type=hidden name=stop value=1 /> </div> <div align=left> <input type=hidden name=name value=111 /></div> <div align=left> <input type=hidden name=number value=222 /></div>"); printf("<div align=left><input type=submit value=login /></div> </form> "); if(stop[0]==1) { printf("%c",stop[0]); *runflag=0; }*/ /* printf("runflag: %d",cginum); fprintf(cgiOut, "</BODY> "); fprintf(cgiOut, "</HTML> ");*/ flag=0; return 0; }
Makefile文件:
login.cgi:cgic.h cgic.c gcc login.c cgic.c -o login.cgi clean: rm -f *.o *.a *.cgi
输入 http://192.168.1.103/cgi-bin/demo/login.cgi