login ---> sqlite--html---cgi(code)

来源:互联网 发布:2016年网络剧大全 编辑:程序博客网 时间:2024/06/07 07:15
//login.c#include <stdio.h>#include <stdlib.h>#include <sqlite3.h>#include <cgi.h>int rscallback(void *p, int argc, char **argv, char **argvv){*(int *)p = 0;//根据查询结果改变empty的值return 0;}int main(){int ret;sqlite3 *db;char *sql = NULL;int empty = 1;char *err = NULL;cgi_init();cgi_process_form();ret = sqlite3_open("user.db", &db);if(ret != SQLITE_OK){printf("Content-Type:text/plain\r\n\r\n");printf("database open error!\n");cgi_end();exit(1);}if((!cgi_param("UserName")) || (!cgi_param("password"))){printf("Content-Type:text/plain\r\n\r\n");printf("username and password must be entered!\n");sqlite3_close(db);cgi_end();exit(1);}elsesql = sqlite3_mprintf("select * from user where username=%Q and password=%Q;", cgi_param("UserName"), cgi_param("password"));//sql = sqlite3_mprintf("select * from user where username=%Q and password=%Q;", "akaedu", "123");ret = sqlite3_exec(db, sql, rscallback, ∅, &err);if(ret != SQLITE_OK){fputs(err, stderr);sqlite3_close(db);cgi_end();exit(1);}if(empty)//登录失败{cgi_redirect("/login_err.html");}else //登录成功cgi_redirect("/login_ok.html");sqlite3_close(db);cgi_end();return 0;}


login.html

<html><head> <meta http-equiv="content-type" content="text/html;charset=UTF-8"></head><body><table width="100%" height="100%" border="0"><tr><td align=center valign=bottom><img src="/images/admin_main_img_help.gif"></td></tr><tr><td align=center valign=top><form action='/cgi-bin/login.cgi' method=POST><table border="0" cellpadding=0 cellspacing=0><tr align=center valign=middle style="height: 49px"><td><b>用户名:</b><input type='text' name='UserName' size=50><br><b>密  码:</b><input type='password' name='password' size=50></td><td><input type="submit" value=" " style="background-image: url(/images/admin_login.gif);border: none;cursor: hand;width:85px;height:49px"><!--input type="submit" value="登录" style="height: 49px;width: 85px"--></td></tr></table></form><embed src="/music/1.mp3" hidden="true" autostart="true" loop="true"></td></tr></table></body></html>