Here is the code you can use to password protect a web page quickly and easily.
If the web page you wish to password protect is an HTML page, open it in a text editor and save it as a PHP page.
Copy and paste this code at the very top of the page you have open in a text editor:
<?php // Define your username and password
$username = "someuser";
$password = "somepassword";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?>
<h1>Login</h1>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtUsername">Username:</label>
<br /><input type="text" title="Enter your Username" name="txtUsername" /></p>
<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>
<?php } else { ?>
<p>This is the protected page. Your private content goes here.</p>
<?php } ?>
First, you will obviously need to define the username and password that you want to use to protect the page.
Next, replace the text that says “This is the protected page…” in the code you just added to your page with the content of the web page that you want to be password protected.
You can password protect just one particular part of your web page if you want to by copying and pasting the code above into wherever on your web page you want to password protect, as long as the web page is a php page. See this post for an example of a web page with only part of it’s content password protected.
Note: if you are trying to password protect just one section of your web page, please refer to my next post on how to password protect part of a web page.

[...] trying to make the entire webpage password protected, please refer to my previous post which covers how to password protect a web page Categories: HTML, PHP | Tags: html, page, password, php, protect, web Password protect a [...]
I’m having trouble getting the login to go to comstockadventure.com
When I publish the site, it shows http://www.comstockadventure.com underneath the login as well.
This is my code
Login
<form name="form" method="post" action="”>
Username:
Password:
http://www.comstockadventure.com
Hi Barbie,
I am having trouble understanding what the issue is exactly. Please feel free to email me at libby@thelibzter.com if you want to discuss the issue further. Thanks!