perl web编程

用Apache和Perl建立一个网站

1.CGI.pm

1.1 查看已经安装的perl模块 : find `perl -e ' print "@INC" ' ` -name ' *.pm '  -print  | grep CGI

       确定CGI模块是否安装.

1.2 配置Apache以允许CGI.

    ScriptAlias /cgi/ /home/httpd/cgi-bin/      #配置路径

    <Directory /home/httpd/cgi-bin>   #配置权限
    Options +ExecCGI
    Order allow,deny
    Allow from all
    </Directory>


1.3  上传文件

    index.html

<html>
<body>
<form method="POST" action="/cgi/test.cgi" ENCTYPE="multipart/form-data">
FILE:
<input type="file" name="FILE">
<br>
<input type="submit" value="Upload!">
</form>
</body>
</html>

test.cgi

#!/usr/bin/perl -w
use CGI;

print "Content-type: text/html/n/n";
my $q = new CGI;
my $file = $q->param("FILE");
print "$file<br>";
my $filename = $file;
$filename =~ s/^.*(open (OUTFILE, ">$basedir/$fileName");
binmode(OUTFILE);
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);

1.4 获取网页访问次数

读取apache的access_log文件获取网页的访问次数.

$num = `grep -c 'GET / HTTP' /apache_path/logs/access_log` ;

1.5 自动刷新网页

<meta http-equiv="refresh" content="300; url=target.html">
    并不是perl web编程 但很有用.

The Common Gateway Interface (CGI) is the workhorse of Web-based application development.

CGI.pm

 

Resources: CGI.pm        http://stein.cshl.org/WWW/software/CGI/cgi_docs.html HTML::Template        http://html-template.sourceforge.net/ Apache/mod_perl        http://perl.apache.org/           <<Professional Perl Development>>  Randy Kobes 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值