本文整理匯總了PHP中Guest::auth方法的典型用法代碼示例。如果您正苦於以下問題:PHP Guest::auth方法的具體用法?PHP Guest::auth怎麽用?PHP Guest::auth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Guest
的用法示例。
在下文中一共展示了Guest::auth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: go
public function go()
{
try {
// select visitor type (user or guest)
if (self::CheckSession()) {
$visitor = new User($_SESSION['user']['name']);
} elseif (self::checkCookies()) {
$visitor = new User($_COOKIE['name']);
} else {
$visitor = new Guest();
}
// select action
$action = $visitor->getAction();
// perform action
if ($action) {
switch ($action) {
case "login":
if ($visitor->auth()) {
$visitor = new User($visitor->getName());
$visitor->login();
}
break;
case "register":
if ($visitor->register()) {
$visitor = new User($visitor->getName());
$visitor->login();
}
break;
case "logout":
$visitor->logout();
break;
case "delete":
$visitor->remove();
break;
}
$this->reload();
}
// show html
if ($visitor instanceof User) {
$this->templateVars['name'] = $visitor->getName();
$this->templateVars['id'] = $visitor->getId();
$this->templateVars['regdate'] = $visitor->getRegDate();
$this->templateVars['lastvisit'] = $visitor->getLastVisit();
$this->showTemplate('inner');
} elseif ($visitor instanceof Guest) {
if (isset($_SESSION['message'])) {
$this->templateVars['message'] = $_SESSION['message'];
unset($_SESSION['message']);
}
if (isset($_SESSION['guest']['entered_name'])) {
$this->templateVars['entered_name'] = $_SESSION['guest']['entered_name'];
unset($_SESSION['guest']['entered_name']);
}
$this->showTemplate('login');
} else {
throw new \Exception();
}
} catch (\Exception $e) {
$_SESSION['message'] = $e->getMessage();
$this->reload();
}
}