Single-Page Password Protection


/ Published in: PHP
Save to your folder(s)

Makes a password protection system for single webpages.


Copy this code and paste it in your HTML
  1. <html>
  2. <head>
  3. <title>Private Page</title>
  4. </head>
  5. <body>
  6.  
  7. <?php
  8. $password = "phpmac";
  9.  
  10. if (!isset($_POST['submit'])) {
  11. ?>
  12. <form action="" method="POST">
  13. Enter the Password: <input type="password" name="password"><br>
  14. <input type="submit" name="submit">
  15. </form>
  16. <?php
  17. } else {
  18.  
  19. if ($_POST['password'] == $password) {
  20.  
  21. ?>
  22.  
  23. Secret content!
  24.  
  25. <?php
  26. } else {
  27. ?>
  28.  
  29. <form action="" method="POST">
  30. Enter the Password: <input type="password" name="password"><br>
  31. <input type="submit" name="submit">
  32. </form>
  33.  
  34. <?php
  35. }
  36. }
  37. ?>
  38.  
  39. </body>
  40. </html>

URL: http://www.phpmac.com/articles.php?view=242

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.