#!/usr/bin/perl -w #!C:/Perl/bin/perl -w # # GET method による CGI呼び出しで、 # QUERYのパラメータの順番を統一させる方法 # [使われないパラメータについては消去される] # use strict; use CGI; my $cgi = new CGI; use vars qw($BASE_HTTP $CGI_SCRIPT); $BASE_HTTP = 'http://www.foo.com/'; $CGI_SCRIPT = 'query.cgi'; # 調整した後と調整する前でQUERYの値が違う場合は # 302 FoundとLocationで再呼び出しする my $reg_query = regularization($cgi); location($reg_query) if ($ENV{'QUERY_STRING'} ne $reg_query); # # 〜〜〜〜〜〜何らかの処理〜〜〜〜〜〜 # print "Content-Type: text/html; charset=EUC-JP\n\n"; print << "HTML"; QUERY regularization

QUERY regularization

'foo', 'bar', 'baz', 'qux', 'grault', 'xyzzy', 'foobar', 'thud', 'fred' という順番でCGI QUERY_STRINGが変更されていればOKです。

HTML exit; ########################################################################## # QUERYを並べ替える # ########################################################################## sub regularization{ my $cgi = shift; # 並び替える順番をここで指定 my @reg = ( 'foo', 'bar', 'baz', 'qux', 'grault', 'xyzzy', 'foobar', 'thud', 'fred', ); # QUERYを並べ替える my $new_query = ''; for(my $i=0;$iparam($reg[$i]); next unless(defined($data)); $new_query .= "$reg[$i]=" . uri_escape($data) . ';' ; } chop($new_query); # よけいな[;]を除去 return $new_query; } ########################################################################## # URIエスケープ # ########################################################################## sub uri_escape{ my $arg = shift; $arg =~s/([^a-zA-Z0-9_.!~*'()-])/sprintf("%%%02X", ord($1))/eg; $arg =~tr/ /+/; return $arg; } ########################################################################## # Locationを出力する # ########################################################################## sub location{ my $query = shift; print "Status: 302 Found\n"; print "Location: $BASE_HTTP$CGI_SCRIPT?$query\n\n"; exit; }