Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Struggling with cgi

Posted on 2002-04-23
6
Medium Priority
?
334 Views
Last Modified: 2013-11-18
Hi,
First I am not a regular Perl user so please bear with me.  I have a cgi script that I am currently using in a vb project to log visitors to a FTP site.  I need to expand the cgi script to accept a few more parameters.  In the existing code there is an extra parameter that is remmed out with the "#" character.  I unremmed this argument and then added it to the Print line.  I also changed the name of the text file that it is creating/writing to.  I did this all locally using Notepad.  I Then posted the new cgi script ASCII to the cgi-bin on my server.  I also toggled the Execute property of the new cgi script using CHMOD so that is was checked.  The new text file is not being created.  My first question is does it sound like I have made the changes in a way that has caused my problems?  
And second what is this part of the code doing?

# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
print FILE "This is a test\n"; # First time

I have the rest of the code I just didn't want to post it all.  Thanks for any help you can give me.
0
Comment
Question by:Glowman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:sstouk
ID: 6963022
You have to post the whole script here.
Otherwise we will be talking a "broken phone" conversation.
I could look though the script and see if it valid, even try it on my system to make sure it works and is not a script's problem (if it is).

So, please post the whole script.
0
 
LVL 4

Author Comment

by:Glowman
ID: 6963047
OK.
Thanks for your quick response.  Also does wordwrap affect anything?

#!/usr/local/bin/perl
# Set Variables
$counterfile     = 'IupdLog.txt';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

# Get the input
$link = $ENV{'DOCUMENT_NAME'};



 if ($ENV{'QUERY_STRING'} !~ /sort=\d/ && $ENV{'QUERY_STRING'}) {
     $adjust = '&' . $ENV{'QUERY_STRING'};
 }
 (@args) = split(/&/, $ENV{'QUERY_STRING'});
 foreach $arg (@args) {
     ($arg, $value) = split(/=/, $arg);
     $value =~ tr/+/ /;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
     if (($arg eq 'query') && ($value ne '')) { $ARGS{$arg} = '.*' }
     else { $ARGS{$arg} = $value }
 }
# $sort_order = ($ARGS{'sort'} || 0);
 $username = $ARGS{'username'};
 $file = $ARGS{'file'};
 $iver = $ARGS{'iver'};
 $time = $ARGS{'time'};
 $VAR{'query'} = $ARGS{'query'} if $ARGS{'query'};
 $VAR{'root_name'} = $ROOT_NAME;



# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
 print FILE "This is a test\n"; # First time
# print FILE $username, ",",  $file;
  print FILE $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
  print FILE  $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 , ",",  $time

# print FILE "1'$link\n"; # First time
flock(FILE, 8);
close(FILE);

$counter = '1';

&LocateLink;

 sub LocateLink {
#  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  print "Content-Type: text/html\n\n";
#  print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'},"\n" ;
#  print $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec;
 print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
 print $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 #  "\n\n";
#  print ,"\n\n";

#  print $counter;
  exit;
 }

Thats what I have to work with.
0
 
LVL 4

Author Comment

by:Glowman
ID: 6963134
OK.
Thanks for your quick response.  Also does wordwrap affect anything?

#!/usr/local/bin/perl
# Set Variables
$counterfile     = 'IupdLog.txt';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

# Get the input
$link = $ENV{'DOCUMENT_NAME'};



 if ($ENV{'QUERY_STRING'} !~ /sort=\d/ && $ENV{'QUERY_STRING'}) {
     $adjust = '&' . $ENV{'QUERY_STRING'};
 }
 (@args) = split(/&/, $ENV{'QUERY_STRING'});
 foreach $arg (@args) {
     ($arg, $value) = split(/=/, $arg);
     $value =~ tr/+/ /;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
     if (($arg eq 'query') && ($value ne '')) { $ARGS{$arg} = '.*' }
     else { $ARGS{$arg} = $value }
 }
# $sort_order = ($ARGS{'sort'} || 0);
 $username = $ARGS{'username'};
 $file = $ARGS{'file'};
 $iver = $ARGS{'iver'};
 $time = $ARGS{'time'};
 $VAR{'query'} = $ARGS{'query'} if $ARGS{'query'};
 $VAR{'root_name'} = $ROOT_NAME;



# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
 print FILE "This is a test\n"; # First time
# print FILE $username, ",",  $file;
  print FILE $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
  print FILE  $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 , ",",  $time

# print FILE "1'$link\n"; # First time
flock(FILE, 8);
close(FILE);

$counter = '1';

&LocateLink;

 sub LocateLink {
#  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  print "Content-Type: text/html\n\n";
#  print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'},"\n" ;
#  print $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec;
 print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
 print $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 #  "\n\n";
#  print ,"\n\n";

#  print $counter;
  exit;
 }

Thats what I have to work with.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Glowman
ID: 6963331
OK.
Thanks for your quick response.  Also does wordwrap affect anything?

#!/usr/local/bin/perl
# Set Variables
$counterfile     = 'IupdLog.txt';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

# Get the input
$link = $ENV{'DOCUMENT_NAME'};



 if ($ENV{'QUERY_STRING'} !~ /sort=\d/ && $ENV{'QUERY_STRING'}) {
     $adjust = '&' . $ENV{'QUERY_STRING'};
 }
 (@args) = split(/&/, $ENV{'QUERY_STRING'});
 foreach $arg (@args) {
     ($arg, $value) = split(/=/, $arg);
     $value =~ tr/+/ /;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
     if (($arg eq 'query') && ($value ne '')) { $ARGS{$arg} = '.*' }
     else { $ARGS{$arg} = $value }
 }
# $sort_order = ($ARGS{'sort'} || 0);
 $username = $ARGS{'username'};
 $file = $ARGS{'file'};
 $iver = $ARGS{'iver'};
 $time = $ARGS{'time'};
 $VAR{'query'} = $ARGS{'query'} if $ARGS{'query'};
 $VAR{'root_name'} = $ROOT_NAME;



# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
 print FILE "This is a test\n"; # First time
# print FILE $username, ",",  $file;
  print FILE $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
  print FILE  $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 , ",",  $time

# print FILE "1'$link\n"; # First time
flock(FILE, 8);
close(FILE);

$counter = '1';

&LocateLink;

 sub LocateLink {
#  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  print "Content-Type: text/html\n\n";
#  print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'},"\n" ;
#  print $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec;
 print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
 print $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 #  "\n\n";
#  print ,"\n\n";

#  print $counter;
  exit;
 }

Thats what I have to work with.
0
 
LVL 6

Accepted Solution

by:
sstouk earned 600 total points
ID: 6963431
The problem is in the line:
, ",",  $time

Please either remark it or remove it.
I tested your script on my server.
As soon as I remarked the line, it created a text file and
responded to Internet Explorer's request properly.
0
 
LVL 4

Author Comment

by:Glowman
ID: 6963551
Thanks for your prompt response and trials.
Works great now.  Perl is one tough cookie with its syntax.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question