There is a problem with the session!";
echo $s->log;
exit();
}
$status_msg = "";
if (isset($_POST['method'])) {
/*
Form was submitted, let's validate and test authentication.
*/
if (Validate()) {
if (Auth()) {
/*
Use the session to "remember" that the user is logged in already.
*/
$s->data['logged_in'] = true;
/*
Store the username in the session if you want.
*/
$s->data['username'] = $username;
/*
We need to "remember" what page the user orignally wanted before
we redirected to login. Pull this value from the session, then remove
it from the session.
*/
$dest = $s->data['page_destination'];
unset($s->data['page_destination']);
$s->save();
/*
Finally, redirect to where the user wanted to go.
*/
header("Location: ".$dest);
}
}
} else {
/*
Set form defaults. Perhaps you want to pull the username from a cookie
you've stored on the user's computer. Maybe you don't want to do anything.
*/
$username = "test";
$pword = "test";
}
LoginForm();
/*
Validate() will validate the form data. You can modify this per your
requirements.
*/
function Validate() {
global $username, $pword, $status_msg;
$ret = true;
$username = strip_tags($_POST['username']);
if (strlen($username) == 0) {
$ret = false;
$status_msg .= "You must enter a username.
";
}
$pword = strip_tags($_POST['pword']);
if (strlen($pword) == 0) {
$ret = false;
$status_msg .= "You must enter a password.
";
}
return $ret;
}
/*
Auth() function to validate username and password. You must return either
true or false. Insert your own auth code inside this function. You'll probably
want to test the username and password against an accounts table in your
database or something like that.
*/
function Auth() {
global $username, $pword, $status_msg;
if ($username != "test" || $pword != "test") {
$status_msg .= "Authentication failed
";
return false;
}
return true;
}
/*
LoginForm() outputs the user form to enter username and pword. You can modify
this any way you want for your own look and feel, but keep the hidden "method"
field.
*/
function LoginForm() {
global $username, $pword, $status_msg;
?>