Click to See Complete Forum and Search --> : Need Help New at CGI


Redhead
05-20-2003, 10:51 AM
Hi everyone!

I'm working on a small page where i'm i want to give a password to someone and they can enter it into a html file and if they enter it in right then it takes them to antoher page.

this is what i have

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';
print "Content-type: text/html\n\n";

my $ReadOut = param('ReadOut');
my $filename;

if ($ReadOut=~/123456/) {
$filename = "http://www.blablabla.com/blablabla/page2.htm";
} else {
print "Sorry, you can not access this page.";
}

open (FILE, "http://www.blablabla.com/blablabla/$filename") || &Error('open','file');
my @page = <FILE>;
close FILE;

foreach (@page) {
print;
}


sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}

what do you think should this work.
Thanks Redhead :confused:

jeffmott
05-20-2003, 11:49 AM
if ($ReadOut=~/123456/) {
$filename = "http://www.blablabla.com/blablabla/page2.htm";
} else {
print "Sorry, you can not access this page.";
}

open (FILE, "http://www.blablabla.com/blablabla/$filename") || &Error('open','file');
my @page = <FILE>;
close FILE;Opening and reading the file should be inside the conditional structure (the if block). Otherwise it will display the page to the user whether they get the password correct or not. Also that path to the file cannot be a URI. It must be the path on the server. You'll have to check your server's documentation for the absolute path, unless you use a relative path. Notice also the value of $filename and where it is being interpolated. The resulting string will be "http://www.blablabla.com/blablabla/http://www.blablabla.com/blablabla/page2.htm". And also, always lock the file when reading or writing.use Fcntl qw{:flock};

if ($ReadOut=~/123456/) {
open FILE, '/path/page.html' or &Error('open', 'file');
flock FILE, LOCK_SH or die $!;
print <FILE>;
close FILE or die $!;
}
else {
print "Sorry, you can not access this page.";
}