post2.cgi
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl
use strict;
#CGIモジュールをロード
use CGI;
#CGIモジュールのオブジェクトを生成
my $q = new CGI;
#yournameの値を取得
my $yourname = $q->param('yourname');
#ageの値を取得
my $age = $q->param('age');
#入力値の評価
my @errors;
if($yourname eq '') {
push(@errors, "yourname\t名前を入力してください。");
}
if($age eq '') {
push(@errors, "age\t年齢を入力してください。");
} elsif($age =~ /[^\d]/) {
push(@errors, "age\t年齢には半角数字で入力してください。");
}
#返信用データを生成
my $res_data = "\xEF\xBB\xBF"; #UTF-8用のBOM
if(@errors) {
$res_data .= "NG\n";
for my $error (@errors) {
$res_data .= "${error}\n";
}
} else {
$res_data .= "OK\n";
$res_data .= "yourname\t${yourname}\n";
$res_data .= "age\t${age}\n";
}
#返信用データのサイズを取得
my $content_length = length $res_data;
#データ出力
print "Content-Type: text/plain; charset=utf-8\n";
print "Content-Length: ${content_length}\n";
print "\n";
print $res_data;
exit;