
tucats
Deleted
Jan 30, 2000, 6:04 PM
Post #1 of 5
(341 views)
|
I need to know how to pass variables to this script... the script: #!/usr/local/bin/perl $data_dir = "/home/kidz4day/kidz4dayz-www/cgi-bin/counter/"; $show_date = "1"; $show_link = "0"; $auto_create = "1"; $lock_sec = "3"; $pad_size = "1"; print "Content-type: text/html\n\n"; $count_page = "$ENV{'DOCUMENT_URI'}"; if ($count_page =~ /\/$/) { chop($count_page); } $count_page =~ s/[^\w]/_/g; $lock_file = "$count_page\.lock"; &check_lock($lock_sec); if (-e "$data_dir$count_page") { open(COUNT,"$data_dir$count_page"); $line = <COUNT>; chop($line) if $line =~ /\n$/; close(COUNT); ($date,$count) = split(/\|\|/,$line); } elsif ($auto_create == 1) { &create; } else { &error('page_not_found'); } $count++; $print_count = $count; $count_length = length($count); for ($i = $pad_size;$i > $count_length;$i--) { $print_count = "0$print_count"; } if ($show_date == 1) { if ($show_link =~ /http:\/\//) { print "<a href=\"$show_link\">$print_count</a> visitors since $date"; } else { print "$print_count visitors since $date"; } } else { if ($show_link =~ /http:\/\//) { print "<a href=\"$show_link\">$print_count</a>"; } else { print "$print_count"; } } open(COUNT,">$data_dir$count_page") | | &error('could_not_increment'); print COUNT "$date\|\|$count"; close(COUNT); &clean_up; sub create { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @months = ("January","February","March","April","May","June","July", "August","September","October","November","December"); $year += 1900; $date = "$months[$mon] $mday, $year"; $count = "0"; open(COUNT,">$data_dir$count_page") | | &error('count_not_created'); print COUNT "$date\|\|$count"; close(COUNT); } sub error { $error = shift(@_); if ($error eq 'page_not_found') { print "[TextCounter Fatal Error: This Page Not Found\; Auto-Create Option Disabled]"; } elsif ($error eq 'bad_uri') { print "[TextCounter Fatal Error: This Page Not In Valid URI]"; } elsif ($error eq 'count_not_created') { print "[TextCounter Fatal Error: Could Not Write to File $datadir$count_page]"; } elsif ($error eq 'could_not_increment') { print "[TextCounter Fatal Error: Could Not Increment Counter]"; } exit; } sub check_lock { $time = $_[0]; for ($i = 1;$i <= $time; $i++) { if (-e "$data_dir$lock_file") { sleep 1; } else { open(LOCK,">$data_dir$lock_file"); print LOCK "0"; close(LOCK); last; } } } sub clean_up { unlink("$data_dir$lock_file"); } ##### ok, now i need to be able to send values for the variables...: $show_date = "1"; $show_link = "0"; $auto_create = "1"; $lock_sec = "3"; $pad_size = "1"; from a query... i was shown this subrouting...: sub parseInput() { if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $temp, $ENV{'CONTENT_LENGTH'}); } elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) { $temp = $ENV{'QUERY_STRING'}; } @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)=split (/=/,$item,2); $content=~tr/+/ /; $content=~ s/%(..)/pack("c",hex($1))/ge; $fields{$key}=$content; } } and calling the script by: &parseInput; he said to put this before i tried to get at any of the variables... I have tried all kinds of things... can you show me how to pass variable values through a query... example...: <!--#exec cgi="/cgi-bin/counter.cgi?show_date=1&pad_size=5"--> thank you so much for your time...
|