Имя пользователя:
Пароль:
 

Название темы: Проблема с Apache
Показать сообщение отдельно

Аватара для SantaXP

Старожил


Сообщения: 453
Благодарности: 16

Профиль | Отправить PM | Цитировать


Разобравшись с отображением скриптов в браузере и при изучении в тоё же книги ("Разработка CGI-приложений на PERL") я столкнулся с новой проблемой...
---
И так. В одном из первых примеров скриптов в книге даётся ведение статистики пользователей. А именно занесение информации о пользователях, посетивших твой сайт в таблицу acess_log базы данных visitors на сервере mysqlhost. Сервер apache носит имя localhost. Занеся SetENV visitors@mysqlhost для создания новой переменной окружения в httpd.conf я понял, что по какой то причине переменная не создаётся. Посему слегка модифицировал код своего модуля LogConnect.pm до такого состояния:
Цитата:
package LogConnect
use DBI;
use strict;
sub connect {
my $log_dsn = "DBI:mysql:database=visitors;host=mysqlhost";
my $log_dbh = DBI->connect($log_dsn, "root", "123456");
if (!defined($log_dbh)) {
print "\nerror: \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043a \u0434\u0430\u043d\u043d\u044b\u0445 MySQL:\n";
print DBI->errstr;
print "-" x 25 "\n';
return;
}
}
1;
---
Далее, я написал два скрипта, первый (vislog.cgi) для ведения статистики, а второй (viewlog.cgi) для её отображения. Вот их код:
Цитата:
#!/usr/local/bin/perl5 -wT
#vislog.cgi
use strict;
use POSIX;
use Socket;
use lib qw(.);
use LogConnect;

my $dbh = LogConnect->connect;
my $ip = $ENV{'REMOTE_ADDR'};
my $browser = $ENV{'HTTP_USER_AGENT'};
my $refer = $ENV{'HTTP_REFERER'};
my $here = $ENV{'REQUEST_URI'};

my @digits = split(/\./, $ip);
my $adress = pack("C4", @digits);
my $host = gethostbyaddr($address, AF_INET);

my $time = strftime("%Y-%m-%d %H:%M:%S",gmtime);

my $query = qq(
insert into acess_log values
('$ip','$host','$browser','$here','$referer','$time'));
my $sth = $dbh->prepare($query);
$sth->execute;
$dbh->disconnect;
Цитата:
#!/usr/local/bin/perl5 -wT
#viewlog.cgi
use strict;
use lib qw(.);
use LogConnect;

print "Content-Type: text/html\n\n";

my $dbh = LogConnect->connect;
my $query = qq(select CLIENT from acess_log);
my $sth = $dbh->prepare($query);
$sth->execute;
my %clients;
while (x$_ = $sth->fetchrow) {
$clients{$_}++;
}
$dbh->disconnect;
my @clients = sort {$clients{$b} <=> $clients{$a}};
keys %clients;
print <<HTML;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=KOI8-R">
<title>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043e\u0442\u0447\u0451\u0442</title>
</head>
<body bgcolor="white">
<center><h2>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043e\u0442\u0447\u0451\u0442</h2></center>
<center><h3>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 Web-\u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432</h3></center>
<hr noshade>
<center>
<table border=1 cellpadding=3 cellspacing=3>
HTML
foreach (@clients) {
print qq(<td align=center>$_</td><td align=center>
$clients{$_}</td><tr>);
}
print <<HTML;
</table>
</center>
</body>
</html>
HTML
---
Однако при запуске любого из этих скриптов выдаётся сообщение:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, santaxp@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/1.3.20 Server at localhost Port 80

-------
...Не так страшен чёрт FreeBSD, как ужасен глюк Windows...


Отправлено: 23:53, 26-06-2005 | #5

Название темы: Проблема с Apache