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 35 36 37 38 39
| <?php
require_once "Auth.php";
function loginFunction()
{
/*
* Change the HTML output so that it fits to your
* application.
*/
echo "<form method=\"post\" action=\"index.php?login=1\">";
echo "<input type=\"text\" name=\"username\">";
echo "<input type=\"password\" name=\"password\">";
echo "<input type=\"submit\">";
echo "</form>";
}
if (isset($_GET['login']) && $_GET['login'] == 1) {
$optional = true;
} else {
$optional = false;
}
$options = array('dsn'=>'mysql://****:*****@localhost/*****');
$a = new Auth("DB", $options, "loginFunction");
$a->start();
echo "Everybody can see this text!<br />";
if (!isset($_GET['login'])) {
echo "<a href=\"index.php?login=1\">Click here to log in</a>\n";
}
if ($a->getAuth()) {
echo "One can only see this if he is logged in!";
echo "<br/><a href='../index.php'>Test session</a>";
}
?> |
Partager