PHP - make webpage password protected

35 views

This trick helps you protect your web page with a help of a password…Here is the code:

  1.  <?
  2. $username = “someuser”;
  3. $password = “somepassword”;
  4.  
  5. if ($_POST[‘txtUsername’] != $username || $_POST[‘txtPassword’] != $password) {?>
  6. <h1>Login</h1>
  7. <form name=”form” method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>”>
  8. <p><label for=”txtUsername”>Username:</label>
  9. <br><input type=”text” title=”Enter your Username” name=”txtUsername”></p>
  10.  
  11. <p><label for=”txtpassword”>Password:</label>
  12. <br><input type=”password” title=”Enter your password” name=”txtPassword”></p>
  13. <p><input type=”submit” name=”Submit” value=”Login”></p>
  14. </form>
  15. <?} else {?>
  16. <p>This is the protected page. Your private content goes here.</p>
  17. <?}?>



« Disable right clicking on page PHP - Optimize database table … Easy trick »
Posted on Monday, March 9th, 2009 at 10:33 am under PHP Tricks | RSS 2.0 Feed

Post Comment

You must be logged in to post a comment.



ComputerEducationWorld.com All Rights Reserved © RSS | CBSE | Education Boards Of India | What is My IP?