错误脚本 额外的环境变量包括cgi 1.1 变量传递给错误脚本。这些cgi 1.1 变量有:
redirect_request :这是当正确发送给服务器的请求。
redirect_url :这是导致错误的请求url。
redirect_status :这是如果ncsa httpd 已经允许应答的状态数字和信息。
另外,ncsa httpd在err_string=error_message时作为ncsa httpd产生的query_string错误字符串传递。一些错误信息可以需要一些不在cgi规范中的文件头。基于这个原因,以下给出一个没有解析的文件头的脚本,它是用perl编写的:
#!/usr/local/bin/perl
# 这是一个利用perl编写的没有解析文件头的cgi 1.1错误脚本来处理错误请求。
$error = $env{'query_string'};
$redirect_request = $env{'redirect_request'};
($redirect_method,$request_url,$redirect_protocal) = split(' ',$redirect_request);
$redirect_status = $env{'redirect_status'};
if (!defined($redirect_status)) {
$redirect_status = "200 ok";
}
($redirect_number,$redirect_message) = split(' ',$redirect_status);
$error =~ s/error=//;
$title = "<head><title>".$redirect_status."</title></head>";
if ($redirect_method eq "head") {
$head_only = 1;
} else {
$head_only = 0;
}
printf("%s %s\r\n",$env{'server_protocol'},$redirect_status);
printf("server: %s\r\n",$env{'server_software'});
printf("content-type: text/html\r\n");
$redirect_status = "<img alt=\"\" src=/images/icon.gif>".$redirect_status;
if ($redirect_number == 302) {
if ($error !~ /http:/) {
printf("xlocation: http://%s:%s%s\r\n",
$env{'server_name'},
$env{'server_port'},
$error);
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("this document has moved");
printf("<a href=\"http://%s:%s%s\">here</a>.\r\n",
$env{'server_name'},
$env{'server_port'},
$error);
}
} else {
printf("location: %s\r\n",$error);
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("this document has moved");
printf("<a href=\"%s\">here</a>.\r\n",$error);
}
}
} elsif ($redirect_number == 400) {
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("your client sent a request that this server didn't");
printf(" understand.<br><b>reason:</b> %s\r\n",$error);
}
} elsif ($redirect_number == 401) {
printf("www-authenticate: %s\r\n",$error);
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("browser not authentication-capable or ");
printf("authentication failed.\r\n");
}
} elsif ($redirect_number == 403) {
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("your client does not have permission to get");
printf("url:%s from this server.\r\n",$env{'redirect_url'});
}
} elsif ($redirect_number == 404) {
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("the requested url:<code>%s</code> ",
$env{'redirect_url'});
printf("was not found on this server.\r\n");
}
} elsif ($redirect_number == 500) {
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("the server encountered an internal error or ");
printf("misconfiguration and was unable to complete your ");
printf("request \"<code>%s</code>\"\r\n",$redirect_request);
}
} elsif ($redirect_number == 501) {
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
printf("the server is unable to perform the method ");
printf("<b>%s</b> at this time.",$redirect_method);
}
} else {
printf("\r\n");
if (!$head_only) {
printf("%s\r\n",$title);
printf("<h1>%s</h1>\r\n",$redirect_status);
}
}
if (!$head_only) {
printf("<p>the following might be useful in determining the problem:");
printf("<pre>\r\n");
open(env,"env");
while (<env>) {
printf("$_");
}
close(env);
printf("</pre>\r\n<hr>");
printf("<a href=\"http://%s:%s/\"><img alt=\"[back to top]\" src=\"/images/back.gif\"> back to root of server</a>\r\n",
$env{'server_name'},$env{'server_port'});
printf("<hr><i><a href=\"mailto:webmaster\@%s\">webmaster\@%s</a></i> / ",
$env{'server_name'},$env{'server_name'});
printf("<i><a href=\"mailto:httpd\@ncsa.uiuc.edu\">httpd\@ncsa.uiuc.edu</a></i>");
printf("\r\n");
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器