Source for file example.php
Documentation is available at example.php
* Test for the LiveUser class
* ===============================
* This example sets up an authorization system using the LiveUser
* class. You don't have to use this to use the LiveUser class(es), but
* this way you don't need to take care of the login-process, storing
* the user object in a session and more...
* This example is intended to be used with the auth XML driver.
* No permission management is supported.
* @version $Id: example.php 203124 2005-12-18 12:41:10Z lsmith $
// Get LiveUser configuration array
if (!isset ($liveuserConfig)) {
die ('<p style="color: red; text-align: center;">The XML file isn\'t readable/writable. Add the right permissions to it and then try again.</p>');
// The error handling stuff is not needed and used only for debugging
// while LiveUser is not yet mature
PEAR ::setErrorHandling (PEAR_ERROR_CALLBACK , 'eHandler');
echo ('<hr /><span style="color: red">' . $errObj->getMessage () . ':<br />'. $errObj->getUserInfo () . '</span><hr />');
class Log_liveuserlog extends Log
function Log_liveuserlog ($name = '', $ident = '', $conf = array (),
$this->_mask = Log ::UPTO ($level);
function log ($msg, $level)
class LU_Default_observer
function notify (&$notification)
echo "observer called on event: " . $notification->getNotificationName () . " \n";
// Create new LiveUser (LiveUser) object.
$obs = new LU_Default_observer ();
$LU->dispatcher ->addObserver (array (&$obs, 'notify'));
$username = (array_key_exists('handle', $_REQUEST)) ? $_REQUEST['handle'] : null;
$password = (array_key_exists('passwd', $_REQUEST)) ? $_REQUEST['passwd'] : null;
$logout = (array_key_exists('logout', $_REQUEST)) ? $_REQUEST['logout'] : false;
} elseif ($username && (!$LU->isLoggedIn () || $LU->getProperty ('handle') != $username)) {
$LU->login ($username, $password);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
font-family: Verdana, Arial, Helvetica, sans-serif;
background-color: #FFFFFF
border-collapse: collapse;
border-top: 1px solid #000;
border-right: 1px solid #000;
// Check if the user has logged in successfully
if (!$LU->isLoggedIn ()) {
<form name="loginform" method="post" action="example.php">
<table width="300" border="0" cellspacing="0" cellpadding="5">
<td colspan="2"><b>Example login</b></td>
<input type="text" name="handle" maxlength="80" value="" />
<input type="password" name="passwd" maxlength="80" value="" />
<input type="submit" value="Login" />
// The user couldn't login, so let's check if the reason was that
// he's not yet been declared "valid" by an administrator.
} else if ($LU->isInactive ()) {
<h3>Sorry kid, but one of our admins has yet approved
your user status. Please be patient. Don't call us -
<p align="center"><a href="example.php?logout=1">Logout</a></p>
<h3>Sorry, we can't let you in. Check if the spelling of
your handle and password is correct.</h3>
<p align="center"><a href="example.php?logout=1">Logout</a></p>
<p><i>Login Data for this Example:</i></p>
<td style="text-align: center; font-weight: bold;">Handle</th>
<td style="text-align: center; font-weight: bold;">Password</th>
<h2 align="center">User logged in: <?php echo $LU->getProperty ('handle'); ?></h2>
<h3>Congrats, you're in</h3>
<p align="center"><a href="example.php?logout=1">Logout</a></p>
// Just some more debug output with no further relevance
print_r($LU->getProperty ('handle'));
Documentation generated on Mon, 11 Mar 2019 15:40:12 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|