使用Perl读取有关服务器的信息

2020年12月29日16:01:15 发表评论 39 次浏览

以下脚本显示了如何使用环境变量查看有关服务器和用户信息的环境变量。佩尔编程语言。

将以下代码插入文本文件, 并以.pl扩展名保存。将文件上传到你的网站空间, 然后通过浏览器访问脚本。

#!/usr/bin/perl -w
#
# V 1.0 / 13.02.2001
#

use CGI qw/:standard fatalsToBrowser/;
use strict;

print header();
print start_html( -title => 'Reading Environment Variables with Perl', -author => 'support@notlogy.com');

print p("Most of the information required for a CGI program is provided by environment variables.  You can access these variables in the same way as any other environment variable (in Perl via %ENV Hash). The following table lists the environment variables usually available for a CGI script.");

print table(
{-border=>'1'}, Tr(
[
th(['Environment variable', 'Content', 'Value for this query']), td(['AUTH_TYPE', 'The authentication method used to verify the user', "$ENV{'AUTH_TYPE'}"]), td(['CONTENT_LENGTH', 'The length of the data transmitted on the form', "$ENV{'CONTENT_LENGTH'}"]), td(['CONTENT_TYPE', 'The format of the form data', "$ENV{'CONTENT_TYPE'}"]), td(['DOCUMENT_ROOT', 'The root directory of your website', "$ENV{'DOCUMENT_ROOT'}"]), td(['GATEWAY_INTERFACE', 'The version of the CGI protocol used', "$ENV{'GATEWAY_INTERFACE'}"]), td(['HTTP_ACCEPT', 'A list of formats accepted by your browser', "$ENV{'HTTP_ACCEPT'}"]), td(['HTTP_COOKIE', 'List of Cookies Sent', "$ENV{'HTTP_COOKIE'}"]), td(['HTTP_FROM', 'Your e-mail address, as provided by your brower', "$ENV{'HTTP_FROM'}"]), td(['HTTP_REFERER', 'The URL of the page which directed you to this CGI program', "$ENV{'HTTP_REFERER'}"]), td(['HTTP_USER_AGENT', 'The name and version of your browser', "$ENV{'HTTP_USER_AGENT'}"]), td(['PATH_INFO', 'Path to CGI script on your webspace', "$ENV{'PATH_INFO'}"]), td(['PATH_TRANSLATED', 'Absolute path to the CGI script', "$ENV{'PATH_TRANSLATED'}"]), td(['QUERY_STRING', 'The form data transmitted to the script', "$ENV{'QUERY_STRING'}"]), td(['REMOTE_ADDR', 'IP address of the visitor', "$ENV{'REMOTE_ADDR'}"]), td(['REMOTE_HOST', 'The resolved IP address of the visitor', '<font color="brightred">Deactivated!</font>']), td(['REMOTE_IDENT', 'Browser user name (UNIX)', "$ENV{'REMOTE_IDENT'}"]), td(['REMOTE_USER', 'Username after authentication', "$ENV{'REMOTE_USER'}"]), td(['REQUEST_METHOD', 'The HTTP request method used for the query', "$ENV{'REQUEST_METHOD'}"]), td(['SCRIPT_NAME', 'Virtual script path', "$ENV{'SCRIPT_NAME'}"]), td(['SERVER_NAME', 'Server name (virtual)', "$ENV{'SERVER_NAME'}"]), td(['SERVER_PORT', 'Server side port number', "$ENV{'SERVER_PORT'}"]), td(['SERVER_PROTOCOL', 'The name and version of the request protocol', "$ENV{'SERVER_PROTOCOL'}"]), td(['SERVER_SOFTWARE', 'HTTP server name and version', "$ENV{'SERVER_SOFTWARE'}"])
]
)
);

print p("Variables are only populated when they are called using CGI scripts.");
print p("Enviromental Variables will not always be populated, for example, REMOTE_USER is only set where the directory or sub-directory is password protected using a .htaccess file, and HTTP_REFERER will only be set where a referral takes place, not where the script is called directly.");

一盏木

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: