最难懂的conf.php的内容放这里
ini_set("include_path", '../libs/PEAR/' . PATH_SEPARATOR . ini_get("include_path"));
require_once 'MDB2.php';
require_once 'LiveUser/LiveUser.php';
$db_name = 'username';
$db_password = 'secret_word';
$db_server = 'localhost';
$db_database = 'db_name';
$dsn ='mysql://' . $db_name . ':' . $db_password . '@' . $db_server . '/' . $db_database;
$db =& MDB2::connect($dsn);
if (PEAR::isError($db))
{
echo $db->getMessage() . ' ' . $db->getUserInfo();
}
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$conf =
array(
'debug' => true,
'session' => array(
'name' => 'PHPSESSION', // liveuser session name
'varname' => 'ludata' // liveuser session var name
),
'login' => array(
'force' => false // should the user be forced to login
),
'logout' => array(
'destroy' => true // whether to destroy the session on logout
),
'cookie' => array(
'name' => 'loginInfo', // name of the Remember me cookie
'lifetime' => 30, // cookie lifetime in days
'path' => null, // cookie path ?
'domain' => null, // cookie domain ?
'secret' => 'test',
'savedir' => '.', // absolute path to writeable directory (no trailing slash) ?
'secure' => false, // whether cookie only send over secure connection
),
'authContainers' => array(
array(
'type' => 'MDB2', // auth container name
'expireTime' => 3600, // max lifetime of a session in seconds
'idleTime' => 1800, // max time between 2 requests
'allowDuplicateHandles' => 0,
'allowEmptyPasswords' => 0, // 0=false, 1=true
'passwordEncryptionMode'=> 'MD5', //密码加密模式
'storage' => array(
'dsn' => $dsn,
'alias' => array( // 附加的或非缺省的字段别名contains any additional
// or non-default field alias
'lastlogin' => 'last_login',
'is_active' => 'is_active',
'owner_user_id' => 'owner_user_id',
'owner_group_id' => 'owner_group_id',
'email' => 'email'
),
'fields' => array( // 附加的或非缺省的字段类型说明contains any additional
// or non-default field types
'lastlogin' => 'timestamp',
'is_active' => 'boolean',
'owner_user_id' => 'integer',
'owner_group_id' => 'integer',
'email' => 'text'
),
'tables' => array( // 增加表或在存在的表中增加字段 contains additional tables
// or fields in existing tables
'users' => array(
'fields' => array(
'lastlogin' => false,
'is_active' => false,
'owner_user_id' => false,
'owner_group_id' => false,
'email' => false
)
)
)
)
)
)
'permContainer' => array(//需要权限系统时才要的
'type' => 'Simple',//哪种权限系统
'storage' => array(
'MDB2' => array( // storage container name
'dsn' => $dsn,
'prefix' => 'liveuser_', // table prefix
'tables' => array(),
'fields' => array(),
'alias' => array()
)
)
)
);
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$LU = LiveUser::singleton($conf);
if (!$LU->init()) {
var_dump($LU->getErrors());
die();
}
$handle = (array_key_exists('handle', $_REQUEST)) ? $_REQUEST['handle'] : null;
$passwd = (array_key_exists('passwd', $_REQUEST)) ? $_REQUEST['passwd'] : null;
$logout = (array_key_exists('logout', $_REQUEST)) ? $_REQUEST['logout'] : false;
if ($logout)
{
// $LU->logout(true);
$LU->logout(false); // does not delete the RememberMe cookie
}
elseif(!$LU->isLoggedIn() || ($handle && $LU->getProperty('handle') != $handle))
{
if (!$handle)
{
$LU->login(null, null, true);
}
else
{
$LU->login($handle, $passwd, false);
}
}