Password protect one section of a web page

Here is the code that you can use to password protect just one section of your web page.

First, open the web page in a text editor.

Next, copy and paste this code into the section that you want to password protect:

// Define your username and password  
$username = "someuser"; 
$password = "somepassword";  
if (
  (isset($_POST['txtUsername']) == false || isset($_POST['txtPassword']) == false) ||
   ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {  ?>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">     
<label for="txtUsername">Username:</label>     
<input type="text" title="Enter your Username" name="txtUsername" />   
<label for="txtpassword">Password:</label>    
<input type="password" title="Enter your password" name="txtPassword" />  
<input type="submit" name="Submit" value="Login" />
<?php  }  else {  ?>  
<p>This is the protected page. Your private content goes here.</p> 
<?php  }  ?>

Make sure to define the username and password you want to use.

Finally, save the page as a PHP page (this is important!) and upload it to your website.

Note: If you are trying to make the entire webpage password protected, please refer to my previous post which covers how to password protect a web page