PHP – Simple Password Protection – No Sessions
Take care of yourself! Read the comments inside!
DOWNLOAD
SELF PAGE PROTECTION
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <html> <body> <!-- SIMPLE PHP PASSWORD PROTECTION WITH NO SESSIONS --> <!-- Author: blog.lucedigitale.com - Andrea Tonin --> <!-- FORM START --> <!-- Il form invia a se stesso PHP_SELF la password con il nome 'password' --> <form method= "post" action= "<?php echo $_SERVER['PHP_SELF'];?>" > Type Password: <input type= "text" name= "password" > <input type= "submit" > </form> <!-- FORM END --> <?php // $_REQUEST colleziona il dato ricevuto dal form $password = $_REQUEST [ 'password' ]; // se la password è corretta visualizza il contenuto HTML nascosto if ( $password == "test" ) { echo " <!-- SECRET CONTENT START --> Password OK!<br> <strong>This is my super HTML formatted secret content!</strong> <!-- SECRET CONTENT END --> "; } else { echo "You need password to enter" ; } ?> </body> </html> |
SPLIT PAGES PROTECTION
You must create in the same folder:
1. password-form.php -> the password form
2. password-reserved.php -> the password protected page
The code for password-form.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <html> <body> <!-- SIMPLE PHP PASSWORD PROTECTION WITH NO SESSIONS --> <!-- Author: blog.lucedigitale.com - Andrea Tonin --> <!-- FORM START --> <!-- Il form invia a password-reserved.php la password con il nome 'password' --> <form method= "post" action= "password-reserved.php" > Type Password: <input type= "text" name= "password" > <input type= "submit" > </form> The password is test <!-- FORM END --> </body> </html> |
The code for password-reserved.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php // $_REQUEST colleziona il dato ricevuto dal form $password = $_REQUEST [ 'password' ]; if ( $password == "test" ) // se la password è corretta visualizza il contenuto HTML nascosto { echo " <!-- SECRET CONTENT START --> <html> <body> Password OK!<br> <strong>This is my super HTML formatted secret content!</strong> </body> </html> <!-- SECRET CONTENT END --> "; } else { // se la password non è corretta visualizza il messaggio di errore echo "You need password to enter" ; } ?> |
SPLIT PAGES PROTECTION + Redirection JavaScript
The code for password-form.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <html> <body> <!-- SIMPLE PHP PASSWORD PROTECTION WITH NO SESSIONS --> <!-- Author: blog.lucedigitale.com - Andrea Tonin --> <!-- FORM START --> <!-- Il form invia a password-reserved.php la password con il nome 'password' --> <form method= "post" action= "password-reserved.php" > Type Password: <input type= "text" name= "password" > <input type= "submit" > </form> The password is test <!-- FORM END --> </body> </html> |
The code for password-reserved.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php // $_REQUEST colleziona il dato ricevuto dal form $password = $_REQUEST [ 'password' ]; if ( $password == "test" ) // se la password è corretta visualizza il contenuto HTML nascosto { echo "<center>Password Corretta</center>" ; } else { // se la password è errata visualizza il messaggio di errore e torna al login echo "<center>Password Errata</center> <script>location.href = 'password-form.php';</script>" ; } ?> <!DOCTYPE html> ... Your Secret Content ... </html> |