latigerlilly
Programmer
Hi,
I have a cgi program written in PERL that takes a URL from an online form and then it writes the URL to a file. However, the colon and two forward slashes get turned into percent 3A percent 2F percent 2F. How do I fix it so I just get a normal URL? Thank you for your help. Below is the actual URL output as it is written in the file.
http%3A%2F%2F
Below is the actual script.
#!/usr/bin/perl
#COMMENT - PARSES DATA FROM THE HTML FORM
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
### assigns values to variables. These variables are from the online form.
$name = $formdata {'name'};
$password = $formdata {'password'};
$pic = $formdata {'pic'};
$link = $formdata {'link'};
$description = $formdata {'description'};
### writes file
open (LOG, ">>/home/mydomain/flock (LOG,2);
print (LOG "$name|$password|$pic|$link|$description\n");
flock (LOG,8);
close (LOG);
print "Content-type: text/html\n\n";
print "Would you like to input another auction? <A HREF=\"
### error message
sub ErrorMessage {
print "Content-type: text/html\n\n";
print "The server can't open the file. It either doesn't exist or the permissions are wrong. \n";
exit;
}
### note: I've changed the actual domain name of my script to mydomain.com so that my server won't
### get hacked into. The program isn't finished writing yet and website safety features aren't
### installed yet. Again, thanks for your help.
I have a cgi program written in PERL that takes a URL from an online form and then it writes the URL to a file. However, the colon and two forward slashes get turned into percent 3A percent 2F percent 2F. How do I fix it so I just get a normal URL? Thank you for your help. Below is the actual URL output as it is written in the file.
http%3A%2F%2F
Below is the actual script.
#!/usr/bin/perl
#COMMENT - PARSES DATA FROM THE HTML FORM
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
### assigns values to variables. These variables are from the online form.
$name = $formdata {'name'};
$password = $formdata {'password'};
$pic = $formdata {'pic'};
$link = $formdata {'link'};
$description = $formdata {'description'};
### writes file
open (LOG, ">>/home/mydomain/flock (LOG,2);
print (LOG "$name|$password|$pic|$link|$description\n");
flock (LOG,8);
close (LOG);
print "Content-type: text/html\n\n";
print "Would you like to input another auction? <A HREF=\"
### error message
sub ErrorMessage {
print "Content-type: text/html\n\n";
print "The server can't open the file. It either doesn't exist or the permissions are wrong. \n";
exit;
}
### note: I've changed the actual domain name of my script to mydomain.com so that my server won't
### get hacked into. The program isn't finished writing yet and website safety features aren't
### installed yet. Again, thanks for your help.