nitic cs exp perl
1.0.0
강의는 2020 년에 문을 열었습니다
counter.cgi웹 페이지가 나타나는 횟수를 계산하려면 카운트 데이터를 저장하려면 파일이 필요합니다. 아래는 기본 Perl CGI 프로그램입니다. 이 프로그램은 카운터 파일을 읽고 카운트를 늘리며 업데이트 된 카운트를 파일 및 웹 페이지에 다시 씁니다.
src/counter.cgi # !/usr/bin/perl
use strict;
use warnings;
use CGI qw( :standard ) ;
# カウンタファイルのパスを指定
my $counter_file = ' counter.txt ' ;
# カウントを取得および更新
open my $fh , ' +< ' , $counter_file or die " Can't open $counter_file : $! " ;
my $count = < $fh >;
$count = 0 unless defined $count ;
$count ++;
seek $fh , 0, 0;
print $fh $count ;
close $fh ;
# HTMLページを出力
print header;
print start_html( ' Counter Page ' );
print " This page has been viewed $count times. " ;
print end_html;이 CGI 프로그램을 실행하려면 다음 단계를 따르십시오.
프로그램 저장 :
counter.cgi 라는 파일에 저장하십시오.실행 권한 설정 :
chmod +x src/counter.cgiXAMPP 구성 :
CGI 디렉토리 구성 :
/Applications/XAMPP/etc/httpd.conf )을 열고 다음과 같이 CGI 디렉토리를 설정하십시오. <Directory "/Applications/XAMPP/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
프로그램 배치 :
ファイルを/Applications/XAMPP/cgi-bin 디렉토리 counter.cgi counter.cgi 기호 링크 counter.cgi 만들려면 터미널을 열고 다음 명령을 실행하십시오 (실제 $ ln -s src/counter.cgi /Applications/XAMPP/cgi-bin/counter.cgi 이 명령은 /Applications/XAMPP/cgi-bin 디렉토리에서 counter.cgi counter.cgi 기호 링크를 만듭니다. 그런 다음 웹 브라우저를 사용하여 http://localhost/cgi-bin/counter.cgi 를 방문하여 CGI 프로그램을 실행할 수 있습니다.
http://localhost/cgi-bin/counter.cgi 로 이동하십시오. 이것이 바로 카운터 프로그램이 실행되고 웹 페이지에 액세스 할 때마다 카운트가 증가해야합니다. 카운터 값은 counter.txt 파일에도 저장되며 프로그램은 해당 파일에서 카운트 값을 읽습니다.