简体   繁体   English

如何在Joomla中设置会话

[英]how to set session in Joomla

I have a website in Joomla which contain course fields. 我在Joomla中有一个网站,其中包含课程字段。

Each course field has different url.I have to check that if user is logged in then it will 每个课程字段都有不同的URL。我必须检查是否已登录用户,它将

redirect to that course.If user is not logged in then it will redirect to login page.how do i 重定向到该课程。如果用户未登录,它将重定向到登录页面。

check using session. 检查使用会话。

Please help me sought it out 请帮我寻找

You have to add JFactory/getUser function to check if user is loged in and if not to use JApplication::redirect to redirect him to desired url. 您必须添加JFactory / getUser函数来检查用户是否已登录,以及是否不使用JApplication :: redirect将其重定向到所需的URL。

$user = JFactory::getUser();
$app = JFactory::getApplication();

if (!$user->guest) {
  echo "You are logged in";
} else {
  $login_url = "index.php?option=com_users&view=login";
  $app->redirect($login_url,'message to display','message');
}

EDIT: 编辑:

There are built in methods in joomla to display content only to registered users without any coding. joomla中内置了一些方法,可以仅向注册用户显示内容,而无需任何编码。

For articles: 对于文章:

Content -> Article Manager -> *Article_name -> Access: Registered

For Menu Items: 对于菜单项:

Menus -> *Menu_name -> *Menu_item_title -> Access: Registered

There is also an option to set redirect link after login. 还有一个选项可以在登录后设置重定向链接。

For Menu item login page: 对于菜单项登录页面:

Menus -> *Menu_Name -> New -> Menu Item Type: (Users Manager -> Login Form) -> Options -> Login Redirect

For Login Module: 对于登录模块:

Extensions -> Module Manager -> New -> Login -> Login Redirection Page

*A quick tip if you haven't login button in your menu is to create a new 'hidden' menu (that won't exist in any frontend position) and place the 'login redirection url' there. *如果您的菜单中没有登录按钮,一个快速提示是创建一个新的“隐藏”菜单(该菜单在任何前端位置都不会存在)并将“登录重定向网址”放置在此处。

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM