#!/usr/local/bin/perl

;# クッキーが使えるかどうかの試験ＣＧＩ v1.00
;#
;# Script written by Kazu.Y
;# Created on: 04/Oct/97
;# Last Modified on: 20/Jun/98
;# Scripts Found at: http://www.rescue.ne.jp/

;# 履歴(History)
;# v0.00 04/Oct/97 初期版
;# v1.00 20/Jun/98 公開版リリース

#----------------#
#    初期設定    #
#----------------#----------------------------------------------------------------------

#このスクリプトのＵＲＬ(httpからフルパスで設定)
$cgi_base_dir = "cookie.cgi";

#body設定
$body = '<body bgcolor=#ffffff>';

#---------------------------------------------------------------------------------------

$modoru = $ENV{'HTTP_REFERER'};
if ($modoru eq '') { &error('処理エラー','参照元ＵＲＬが取得できません.<br>あなたのサーバではご利用できません.'); }

$buffer = $ENV{'QUERY_STRING'};
if ($buffer eq '') { &regist; }
elsif ($buffer eq 'result') { $cookies = $ENV{'HTTP_COOKIE'}; &html; }
else { &error('処理エラー',''); }
exit;

sub html {

	print "Content-type: text/html; charset=Shift_JIS\n\n";
	print "<html><head><title>$title</title></head>\n";
	print "$body\n";
	print "<h1>動作試験結果<hr noshade></h1>\n";

	if ($cookies ne '') { print "ショッピングバスケットが利用可能\です.<p>\n"; }
	else {

		print "あなたのブラウザでは、ショッピングバスケットはご利用できません.<br>\n";
		print "ネットスケープまたはインターネットエクスプローラをご利用ください.<p>\n";
	}

	print "<hr noshade><h3><a href=\"$modoru\">戻る</a></h3>\n";
	print "</body></html>\n";
	exit;

}

sub regist {

	print "Set-Cookie: cookie=$modoru;\n";
	print "Location: $cgi_base_dir\?result\n\n";
	exit;
}

sub error {

	print "Content-type: text/html\n\n";
        print "<html><head><title>$title</title></head>\n";
        print "$body\n";
        print "<h1>$_[0]</h1>\n";
	print "<h3>$_[1]</h3>\n";
	print "ブラウザの[戻る]ボタンを押して前の画面に移動してください.\n";
        print "</body></html>\n";
        exit;
}
