c语言实现cgi程序

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">       在tplink上刷了openwrt固件,  在上面编写了cgi测试程序</span>

        示例如下:

#include <stdio.h>
#include "socket/Net.h"

// test user name and password
int Login(char* sJrmAddr,int nJrmPort,char* sUserNmae,char* sUserPwd);

int main()
{
	printf("Content-type: text/html\n\n");
	printf("<html> <head>\n");
    printf("<title>login result</title>\n");
    printf("</head>\n\n");
    printf("<body>\n");

	char sUserName[32]={0};
	char sUserPwd[32]={0};	


	char* data = getenv("QUERY_STRING");

	int nScanfRet=sscanf(data,"username=%[^&]&userpwd=%s",sUserName,sUserPwd);
	
    if(nScanfRet!=2)
	{
        printf("<script>alert('please input username and password');window.location.href='../login.html'</script>\n");
		return 0;		
    }	
	
	printf("</body> </html>\n");	
	
	return 0;
}

html 登录页面 如下

<html>
<head>  
<title>jbox login</title> 

</head>  
<body bgcolor="gray" style="color:white">
<h1 align="center" style="margin-top:200px;">jbox login </h1>
<table align="center" >  
<tr><td>  
<form method="GET" action="./cgi-bin/jbox-cgi.cgi">
username: <input style="width:200px;height:20px;" type="txt" size="3" name="username"><br><br>
password: <input style="width:200px;height:20px;" type="password" size="3" name="userpwd"><br><br>
<input style="margin-left:100px;width:100px;height:30px;" type="submit" value="login">  
</form>
</td></tr>  
<tr>
<td></td>
</tr>  
</table>  
</body>  
</html>


示例下载地址:   http://download.csdn.net/detail/mtour/8243601

   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值