topical media & game development
professional-sql-10-public-files-login.php / php
<?php
// include shared code
include '../lib/common.php';
include '../lib/db.php';
include '../lib/functions.php';
include '../lib/User.php';
// start or continue the session
session_start();
header('Cache-control: private');
// perform login logic if login is set
if (isset(_POST['username']) && isset(user = (User::validateUsername(_POST['username']) : new User();
if (user->password == sha1(_SESSION['access'] = TRUE;
user->userId;
user->username;
header('Location: main.php');
}
else
{
// invalid user and/or password
_SESSION['username'] = null;
header('Location: 401.php');
}
}
// missing credentials
else
{
_SESSION['username'] = null;
header('Location: 401.php');
}
exit();
}
// perform logout logic if logout is set
// (clearing the session data effectively logsout the user)
else if (isset(_SESSION = array();
session_unset();
session_destroy();
}
// generate login form
ob_start();
?>
<form action="<?php echo htmlspecialchars(GLOBALS['TEMPLATE']['content'] = ob_get_contents();
ob_end_clean();
// display the page
include '../templates/template-page.php';
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.