CGI计数器

1:count.cgi源码

#if 1
#define SERVER_NAME cgiServerName
#endif
#if 0
#define SERVER_NAME "www.boutell.com"
#endif

#ifdef WIN32
#define SAVED_ENVIRONMENT "c:\\cgicsave.env"
#else
#define SAVED_ENVIRONMENT "/tmp/cgicsave.env"
#endif 

#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
void ShowForm();
void Count();

int cgiMain() 
{


cgiHeaderContentType("text/html");

fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
fprintf(cgiOut,"<BODY>");

ShowForm();
Count();

fprintf(cgiOut, "</BODY></HTML>\n");
return 0;
}

void Count()
{
int i = 0;
int j = 9;
int fd;
int a[10];
unsigned int  count = 0;
int count2          = 0 ;
fd                  = open("count1.txt",O_RDWR|O_CREAT,S_IWOTH|S_IROTH);
if(fd==-1)
{
perror("open");
}
        count2               = read(fd,&count,sizeof(count));
close(fd);
count++;
fd = open("count1.txt",O_RDWR|O_CREAT,S_IWOTH | S_IROTH);
if(fd==-1)
{
 perror("open");
}
write(fd,&count,sizeof(count));
       // printf("%d\n\n",sizeof(count));
printf("<p>不是图形显示的计数器<p>");
printf("%08u\n",count);
close(fd);

//fprintf(c);
fprintf(cgiOut, "\n");
fprintf(cgiOut, "<p>图形界面显示的计数器<p>\n");


while(count)
{
 i = count%10;  
          count=count/10;
          a[j--] = i;
          fprintf(cgiOut,"\n");
}
while(j != -1)
{
  a[j--] = 0;
}
 
j = 0;
while( j<10 )
{
    switch(a[j++])
     {
   case 0:
    fprintf(cgiOut,"<img border=\"0\" src=\"/images/0.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 1:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/1.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 2:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/2.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 3:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/3.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 4:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/4.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 5:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/5.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 6:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/6.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 7:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/7.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
        case 8:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/8.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   case 9:
     fprintf(cgiOut,"<img border=\"0\" src=\"/images/9.gif\" width=\"30\" height=\"30\" align=\"absmiddle\"></a>\n");
     break;
   }
}
}
void ShowForm()
{
fprintf(cgiOut, "<!-- 2.0: multipart/form-data is required for file uploads. -->");
        fprintf(cgiOut,"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
fprintf(cgiOut, "<form method=\"POST\" enctype=\"multipart/form-data\" ");
fprintf(cgiOut, " action=\"");
cgiValueEscape(cgiScriptName);
fprintf(cgiOut, "\">\n")     ;
fprintf(cgiOut, "</form>\n") ;
}



2:makefile



3:传送到相应文件夹的脚本


主要是传一个目录就可以了,然后必须要改变文件的执行属性。

4:执行的效果


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值