Can anyone tell me how it's done? I'm completely new to CGI so a long spiel would be most helpful :)
Printable View
Can anyone tell me how it's done? I'm completely new to CGI so a long spiel would be most helpful :)
what are you talking about?
Someone goes to a site, the first thing they see is a password access screen. They type in a password and if it's correct they are redirected to another page.
Sorry about that, I tend to be too vague in my descriptions...
I haven't tried this yet, but it should work.Code:#!/usr/bin/perl
print "Content-type: text/html\n\n\n";
require("inc.cgi");
open(FILE, ">>$tfname");
sub GetFormInput {
(*fval) = @_ if @_ ;
local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
$i = 0;
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";
#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}
if($i eq 0) {
print FILE "\"$val\"";
} else {
print FILE ",\"$val\"";
}
}
print FILE "\n";
}
close(FILE);
return 1;
}
&GetFormInput;
if($field{"pass"} eq "mypass" && $field{"user"} eq "username"){
print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=urltoredirectto\">";
} else {
print "Wrong username or password";
}
-Dennis
Thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you
It didn't work...
try that.Code:#!/usr/bin/perl
print "Content-type: text/html\n\n\n";
sub GetFormInput {
(*fval) = @_ if @_ ;
local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";
#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}
}
}
return 1;
}
&GetFormInput;
if($field{"pass"} eq "mypass" && $field{"user"} eq "username"){
print "<META HTTP-EQUIV=\"refresh\" CONTENT=0; URL=http://www.olemac.net\">";
} else {
print "Wrong username or password";
}
It still doesn't work
BTW I finally saw blazing saddles yesterday on comedy central, that scene was hilarious :D