Home
Articles
Forums
Resources
Downloads
Search
Last Visit
Get Album Art
Embed Codes
Music Playlists
Music Search
Member Links
Login Form
Username: Password:
Login with username, password and session length

Forgot your password?
Support The Cause

Home arrow Articles arrow PHP Code Snippets arrow Simple Password Protect
Simple Password Protect PDF Print E-mail
User Rating: / 0
PoorBest 
PHP - PHP Code Snippets
Written by Jason   
Jan 03, 2008 at 01:54 PM

This is a very basic example for password protecting a page.
Create a file (whatever.php) using the following code and insert your own password where PASSWORD is defined.
Code:

 <?php
define('PASSWORD','abc123'); // YOUR PASSWORD HERE
session_start();
if(!isset($_SESSION['pass'])){
$pass = $_REQUEST['pass'];
}
if($pass == PASSWORD){
$_SESSION['pass'] = "true";
} else {
unset($pass);
unset($_SESSION['pass']);
}
if(isset($_SESSION['pass'])){
echo "You Passed!";
// PROTECTED CONTENT HERE
} else {
// UNPROTECTED CONTENT
echo "<form name=\"login_form\"
method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">
<b>Password:</b> <input type=\"password\" name=\"pass\">
<input type=\"submit\" name=\"Submit\" value=\"Submit\">
</form>";
}
?>


User Comments
Please login or register to add comments

<Previous