<?php
if (isset($_SESSION['auth']["username"])) {
echo "Welcome <a href='index.php?option=com_user&view=user&task=edit'>"
. $_SESSION['auth']["username"]
. "</a>!";
} else {
echo "<a href='index.php?option=com_user&view=login'>Log in</a>";
}
?>
$_SESSION['auth'] 中$_SESSION['auth']["username"] 為登入用戶名<?php
$user = JFactory::getUser();
if ($user->id) {
echo "Welcome <a href='" . JRoute::_('index.php?option=com_user&view=user&task=edit') . "'>"
. htmlspecialchars($user->username)
. "</a>!";
} else {
echo "<a href='" . JRoute::_('index.php?option=com_user&view=login') . "'>Log in</a>";
}
?>
優勢: 使用框架內置用戶對象,自動處理會話驗證、ACL 權限、多站點上下文,代碼更健壯、可移植。