Thread: parseinput()

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    18
    Rep Power
    0
    my question is how do i pass variable information to this script using a query...

    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/htmlnn";

    $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") &#0124; &#0124; &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") &#0124; &#0124; &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...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    18
    Rep Power
    0
    don't answer...

    i already figured it out...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    I'm telling ya... happens every time.. You post a question thats been like a bug up your butt for the last week, and 5 minutes (or in your case 21 hours) you've got it figured out.

    Totally autonomous help system!!!!

    Mike

IMN logo majestic logo threadwatch logo seochat tools logo