PPP0_ Гость
|
Добавлено: Пт Дек 03 2004 13:35 Заголовок сообщения: perl cookies ? где ошибка ? |
|
|
вот такой трабл : скрипт не пишет куки
посмотрите исходник пожалуйста .. помогите .. потому что за..
короче полная попа...
вот код:
сам скрипт--------------------------------
Код: | #!/usr/bin/perl
require ("$ENV{DOCUMENT_ROOT}cms.conf.pl") or &err("check directory: $includes_directory") ;
require ("$includes_directory/mod.pl") or &err("check directory: $includes_directory") ;
require("$main") or &err("check directory: $includes_directory") ;
$|=1 ;
require "cgi-lib.pl";
ReadParse(*in);
$news_id=$a=$b=$c=$d=$s=$t=$g=$y=0;
if ($banner_rotate ne "0") { require ("$ad_cycle_file"); }
require("$counter_file") or &err("check directory: $includes_directory") ;
&read_counter_data("$log_file");
$counted=@read_counter_data;
&read_user_session;
&clicks;
&randomize;
sub read_user_session {
if ($ENV{"HTTP_COOKIE"} ne "") {
use CGI qw/:standard/;
use CGI::Cookie;
%cookies = fetch CGI::Cookie;
if (defined ($cookies{'UID'})) {$UID = $cookies{'UID'}->value; }
%cookies = parse CGI::Cookie($ENV{HTTP_COOKIE});
($userID,$host,$ip,$c_user,$ref)=split(/---/,$UID);
}
}
&create_user_session;
foreach $all_data (keys %in)
{
$in{"$all_data"}=~s/\.\.\//index.html/ixg;
$in{"$all_data"}=~s/\%/index.html/ixg;
}
&read_main_file("$main_file") or &error("$!");
&read_news2("$templates_directory$news_template") or &error("$!");
&read_counter_data("$log_file") or &error("$!");
&read_news("$news_file") or &error("$!");
&whos_online or &error("$!");
&read_all_news or &error("$!");
$query_template="forparse.html" ;
&read_main("$query_template") or &error("$!");
sub whos_online {
$visitors="1";
open(DATA, "$data_file");
my @data=<DATA>;
close(DATA);
foreach my $data_value (@data){
my($logged_ip, $logged_time) = split(/\|/, $data_value);
my $time_diff=$time_now-$logged_time;
push(@new, $data_value) if ($time_diff <= $timeout);
}
open(UPDATED, ">$data_file");
foreach my $record (@new) {
my($logged_ip, $logged_time) = split(/\|/, $record);
print UPDATED "$record" if ($visitor_ip ne $logged_ip);
$visitors++ if ($visitor_ip ne $logged_ip);
}
print UPDATED "$visitor_ip|$time_now\n";
close(UPDATED);
}
sub read_all_news{
$all_news.="<table border=0 cellpading=0 cellspacing=0 width=\"100%\"><tr>";
foreach $all (@news){
($news_title,$news_body,$news_date,$news_picsmall,$news_picbig,$pcat,$keywords2)=split(/\^/,"$all");
$all_news.="<td>";
for ($f=0;$f<@news2 ;$f++)
{
if ($pcat eq "yes") {
$f++ ;
}
else{
&read_news2("$templates_directory$news_template") or &error("$!");
$news2[$f]=~s/images\//\/images\//ixg;
$news2[$f]=~s/\?news\=/\/\?news\=/ixg;
$news2[$f]=~s/\%category_slides_folder\%/$images_folder_url/ixg;
$news2[$f]=~s/\%category_slides_folder2\%/$images_folder_url/ixg;
$news2[$f]=~s/\%news_title\%/$news_title/ixg;
$news2[$f]=~s/\%news_body\%/$news_body/ixg;
$news2[$f]=~s/\%news_date\%/$news_date/ixg;
$news2[$f]=~s/\%news_id\%/$news_id/ixg;
$news2[$f]=~s/\%news_picbig\%/$news_picbig/ixg;
$news2[$f]=~s/\%news_picsmall\%/$news_picsmall/ixg;
$all_news.= "$news2[$f]" ;
}
}
if ($aaaa==($news_cols-1)) { $all_news.="</tr><tr>"; $aaaa=-1; }
$aaaa++;
$all_news.="</td>";
$news_id++;
}
$all_news.="</tr></table>";
}
use DBI;
$dbh=DBI->connect($cms_dsn) or &sql_error(DBI->errstr,1);
$sth = $dbh->prepare( "select * FROM $pay_phone ORDER BY id;");
$sth->execute or &sql_error($dbh->errstr,2);
$i=0;
while ((@results=$sth->fetchrow) != NULL) {
$i++;
$last=$results[0];
$last_randid=$results[2];
}
$last++;
$sth->finish;
$dbh->disconnect; |
-------------------------------------------
а вот модуль сам :
------------------------------------
Код: | sub create_user_session {
&randomize;
use CGI qw/:standard/;
use CGI::Cookie;
%cookies = fetch CGI::Cookie;
$ip = $ENV{'REMOTE_ADDR'};
@digits = split (/\./, $ip);
$address = pack ("C4", @digits);
$host = gethostbyaddr ($address, 2);
$host_tmp="$host";
@tmp_host=split(/\./,$host_tmp);
$tmp_host[0]=~s/http\:\/\///ixg;
$c_user="$tmp_host[0]";
if (!defined ($cookies{'UID'})) {
$newcookie = new CGI::Cookie(
-name=>'UID',
-value=>"$rand---$host---$ip---$c_user---$ENV{HTTP_REFERER}",
-expires => "$cookie_expires",
-path => '/',
-secure => "$secure_cookie"
);
#print header(-cookie=>$newcookie);
print "Set-Cookie: $newcookie\n";
#print "Set-Cookie: cookie-name=UID;value=$rand---$host---$ip---$c_user---$ENV{HTTP_REFERER}; path=/; expires=$cookie_expires\n\n";
#print "$newcookie"; |
-----------------------------------------
[/code] |
|