How do I password protect an html file using a dialup service?

They have: 2 posts

Joined: Jun 2000

I use a dialup ISP. I have a home page that I would like to restrict access to some of the links. I saw a similar question asked in the HTML forum, and that person was referred here?

Thank you.

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

If your ISP doesn't allow you to use .htaccess files to restrict access to a certain folder, then you could use a cgi-script that requires password authentication, and then redirects the user to the protected file. I haven't done this before but I imagine that it could be accomplished with something like this.

code:


#!/usr/bin/perl -w

require "formparser.cgi"; # you need some way to parse the form as well.

if (mode eq "") {
print "Content-type:text/html\n\n";
print "<html><head><title>PASSWORD FORM</title></head><body>";
print "<form method="POST" action="thisscript.cgi?mode=pass";
print "<input type="text" name="username">";
print "<br><input type="password" name="password">";
print "<input type="submit" value="SUBMIT">";
print "</form>";
print "</body></html>";

if (mode eq "pass") {
 open (PASSWORDS, "< ../passwords.txt");
 @passes = <PASSWORDS>;
 close (PASSWORDS);

foreach $item(@passes) {
 if ($pass = $item) {
  $access = "yes"
 }
}

if ($access eq "yes") {
 redirect # I forget how to redirect???
} else {
print "Content-type:text/html\n\n";
print "Sorry that password is incorrect";
}

[/code]

Now this is just a simple script that I typed on the fly so use it as a guide don't try and use it on the server because it will not execute because I haven't escaped the quotation marks.

I hope this helps some.
VulKen
I'm Too Phat 

Pimpin like a pimp with an electrofied pimpin machine!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.