Password protect web pages
Posted: Sun May 07, 2006 11:02 am
You can password protect your website using two methods:
1) Use authentication of your webserver
http://www.hwg.org/lists/hwg-servers/passwords.html
2) Using PHP scripting.
Here's a small example (your webhost must support PHP)
a. Create a form using Web Builder.
b. Set these properties:
Name: LoginForm
Method: POST
Action: <?php echo($HTTP_SERVER_VARS["PHP_SELF"]);?>
Encoding type: make this field empty
c. Add an editbox to the form for the username:
Name: username
d. Add an editbox to the form for the password:
Name: password
e. Add a button:
Name: Login
Type: submit
f. Open Page HTML and enter this code to Start of Page:
<?php
session_start();
if (!empty($HTTP_POST_VARS))
{
if ($HTTP_POST_VARS["password"] == "WebBuilderIsCool")
{
if (!isset($HTTP_SESSION_VARS["logged_in"]))
{
$username= $HTTP_POST_VARS["username"];
$password = $HTTP_POST_VARS["password"];
$logged_in = "YES";
session_register("username");
session_register("password");
session_register("logged_in");
header("Location: logged_on.html");
}
else
{
echo("<h2>Session expired!<br>Please try again later.<br></h2>");
exit;
}
}
else
{
echo("<h2>Invalid password!<br>You're not logged on.<br></h2>");
}
}
?>
g. Save this page as login.wbp and make sure the publish extension is php
h. Note that once the user has been succesfully logged on it will be redirected to logged_on.html (so make sure this page also exist)
i. Now on every page you want to protect insert this code in the Start of Page section:
<?php
session_start();
if ($HTTP_SESSION_VARS["logged_in"] != "YES")
{
header("Location: http://www.yourdomain.com/login.php");
exit;
}
?>
1) Use authentication of your webserver
http://www.hwg.org/lists/hwg-servers/passwords.html
2) Using PHP scripting.
Here's a small example (your webhost must support PHP)
a. Create a form using Web Builder.
b. Set these properties:
Name: LoginForm
Method: POST
Action: <?php echo($HTTP_SERVER_VARS["PHP_SELF"]);?>
Encoding type: make this field empty
c. Add an editbox to the form for the username:
Name: username
d. Add an editbox to the form for the password:
Name: password
e. Add a button:
Name: Login
Type: submit
f. Open Page HTML and enter this code to Start of Page:
<?php
session_start();
if (!empty($HTTP_POST_VARS))
{
if ($HTTP_POST_VARS["password"] == "WebBuilderIsCool")
{
if (!isset($HTTP_SESSION_VARS["logged_in"]))
{
$username= $HTTP_POST_VARS["username"];
$password = $HTTP_POST_VARS["password"];
$logged_in = "YES";
session_register("username");
session_register("password");
session_register("logged_in");
header("Location: logged_on.html");
}
else
{
echo("<h2>Session expired!<br>Please try again later.<br></h2>");
exit;
}
}
else
{
echo("<h2>Invalid password!<br>You're not logged on.<br></h2>");
}
}
?>
g. Save this page as login.wbp and make sure the publish extension is php
h. Note that once the user has been succesfully logged on it will be redirected to logged_on.html (so make sure this page also exist)
i. Now on every page you want to protect insert this code in the Start of Page section:
<?php
session_start();
if ($HTTP_SESSION_VARS["logged_in"] != "YES")
{
header("Location: http://www.yourdomain.com/login.php");
exit;
}
?>