Location: PHPKode > projects > PHP Project Manager > includes/password.php
<?php
// This starts the session
// After you are logged in, you can stay logged in by navigating to
// other pages on the same server with this at the top of the php page.
session_start();

// This is the username and password you login with, you can also use
// a database to get the username and match it up (later tutorial).
require('scripts/db.php');

// If the form was submitted
if ($_POST['Submitted'] == "True") {

    // If the username and password match up, then continue...
    if ($_POST['Username'] == $admin_user_name && $_POST['Password'] == $admin_password) {

        // Username and password matched, set them as logged in and set the
        // Username to a session variable.
        $_SESSION['Logged_In'] = "True";
        $_SESSION['Username'] = $admin_user_name;
    }
}

// If they are NOT logged in then show the form to login...
if ($_SESSION['Username'] != $admin_user_name) {

    echo "
    <html>
    <head>
    <title>Restricted Area - Login Required</title>
    <style>
    body{
	font-size:80%;
	font-family:Georgia,Arial,Verdana,serif;
	width:100%;
	text-align:center;
	background-color:#000000;
    }
    form{
	    width:300px;
	    padding:10px;
	    margin:10px;
	    margin:0 auto;
	    border:1px solid black;
	    background-color:#B1D3EC;
    }
    input{
	    margin-bottom:4px;
	    font-family:Georgia,Arial,Verdana,serif;
	    background-color:white;
	    border:3px double black;
    }
    h1{
	    font-size:100%;
	    color:red;
    }
    </style>
    </head>
    <body>
    <h1>Secure Area - Authentication Required</h1>
    <form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">
    Username:<br /><input type=\"text\" name=\"Username\"><br />
    Password:<br /> <input type=\"password\" name=\"Password\"><br />
    <input type=\"hidden\" name=\"Submitted\" value=\"True\">
    <input type=\"Submit\" value=\"Login\" name=\"Submit\">
    </form>
    <body>
    </html>";
    exit;
}
else
{
    echo "You are logged in as: <strong>" . $_SESSION['Username'] . "</strong>,
     <a href=\"" . $_SERVER['PHP_SELF'] . "?mode=logout\">Logout</a>";
}

// If they want to logout then
if ($_GET['mode'] == "logout") {
    // Start the session
    session_start();

    // Put all the session variables into an array
    $_SESSION = array();

    // and finally remove all the session variables
    session_destroy();

    // Redirect to show results..
    echo "<META HTTP-EQUIV=\"refresh\" content=\"1; URL=" . $_SERVER['PHP_SELF'] . "\">";
}
?> 
Return current item: PHP Project Manager