cgi程序 c语言,C语言编写CGI程序

啥都不说,直接看代码!

简单输出代码

#include

#include

#include

void main()

{

printf("Content-type:text/html\n\n");

printf("hello world!");

fflush(stdout);

}

处理get代码

#include

#include

int zmain(void)

{char *data;

long m,n;

printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);

printf("

Multiplication results\n");

printf("

Multiplication results

\n");

data = getenv("QUERY_STRING");

if(data == NULL)

printf("

Error! Error in passing data from form to script.");

else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)

printf("

Error! Invalid data. Data must be numeric.");

else

printf("

The product of %ld and %ld is %ld.",m,n,m*n);

return 0;

}

处理post代码

#include

#include

void main()

{

int i,n;

printf("Content-type:text/html\n\n");

n=0;

if(getenv("CONTENT_LENGTH"))

n=atoi(getenv("CONTENT_LENGTH"));

printf("%d",n);

for(i=0;i

putchar(getchar());

putchar('\n');

fflush(stdout);

}

还是代码

#include

#include

#include

/* 转换函数声明 */

int htoi(char *);

/*  主函数 */

void zmain() {

int i,n;

char c;

printf ("Content-type: text/html\n\n");

n=0;

if (getenv("CONTENT_LENGTH"))

n=atoi(getenv("CONTENT_LENGTH"));

for (i=0; i

int is_eq=0; //判断是否有等于号。

c=getchar();

switch(c){

case '&':

c='\n';

break;

case '+':

c='+';

break;

case '%':

{

char s[3];

s[0]=getchar();

s[1]=getchar();

s[2]=0;

c=htoi(s);

i+=2;

}

break;

case '=':

c='=';

is_eq=1;

break;

};

putchar(c);

//if (is_eq) putchar(' ');

}

putchar ('\n');

fflush(stdout);

}

/* 转换为小写 */

int islower (int ch )

{

return (unsigned int) (ch - 'a') < 26u;

}

/* convert hex string to int 16进制转换成10进制 */

int htoi(char *s)

{

char *digits="0123456789ABCDEF";

if(islower(s[0])) s[0]=toupper(s[0]);

if(islower(s[1])) s[1]=toupper(s[1]);

return 16 * (strchr(digits, s[0]) -strchr(digits,'0') ) +(strchr(digits,s[1])-strchr(digits,'0'));

}

#include

#include

void zzzmain()

{

int i,n;

printf("Content-type:text/html\n\n");

n=0;

if(getenv("CONTENT_LENGTH"))

n=atoi(getenv("CONTENT_LENGTH"));

printf("%d",n);

for(i=0;i

putchar(getchar());

putchar('\n');

fflush(stdout);

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值