简体   繁体   English

如何在joomla 2.5中创建一个关闭活动会话的按钮

[英]How to create a button to close active session in joomla 2.5

I need to create a button to log out in Joomla, I mean, the user usually enter the session but then must press the button I created to close this session, I know how to check if any user has entered the session and I know how to display the button, what I don't know is how to make that button close the actual user session (log out). 我需要创建一个按钮来注销Joomla,我的意思是,用户通常会进入会话但是必须按下我创建的按钮才能关闭此会话,我知道如何检查是否有用户已进入会话并且我知道如何要显示按钮,我不知道的是如何使该按钮关闭实际的用户会话(注销)。

This is the base code I have: 这是我的基本代码:

<?php $user =& JFactory::getUser(); ?>
<?php if ( ($user->id)==0 ) : ?>

    //***code for not opened session***

<?php else : ?>

    <form id="form1" name="form1" method="post" action="">
      <input type="button" name="button" id="button" value="Close Session" />
    </form>

<?php endif ?>

How to make that button to close the joomla 2.5 session, I checked the API page but i didn't find it. 如何使该按钮关闭joomla 2.5会话,我检查了API页面,但我没有找到它。

To create a log out button, you could create a link with the class "button". 要创建注销按钮,可以使用“按钮”类创建链接。

In Joomla > 1.7 (also 2.5.x) you need the JUtility::getToken() part to make the login successful: Use the optional "return" part for redirecting the user back to the page where the user was when clicking the button 在Joomla> 1.7(也是2.5.x)中,您需要JUtility :: getToken()部分才能使登录成功:使用可选的“返回”部分将用户重定向回用户单击按钮时所在的页面

<a class="button" href="<?php echo JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken().'=1'); ?>">
    Logout
</a>

If you want to redirect back to the page where the user was when he/she clicked the logout button, add a base64 encoded return parameter: 如果要重定向回到用户单击注销按钮时所在的页面,请添加base64编码的返回参数:

<a class="button" href="<?php echo JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken().'=1&return='.base64_encode(JURI::current())); ?>">
    Logout
</a>

实际上是正确的链接

JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken() .'=1');

This also works for joomla 2.5. 这也适用于joomla 2.5。 I swapped JURI::current() with $_SERVER['REQUEST_URI'] from @Beatniak code 我用@Beatniak代码用$ _SERVER ['REQUEST_URI']交换了JURI :: current()

<a class="button" href="<?php echo JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken().'=1&return='.base64_encode($_SERVER['REQUEST_URI'])); ?>">
    Logout
</a>

u may try also this for Joomla 2.5 你可以尝试使用Joomla 2.5

<a href="index.php?option=com_users&task=user.logout&<?php echo JUtility::getToken(); ?>=1">
<input  type="button" name="Submit" class="button" value="Logout">
</a>

works good for me 对我有益

see this link http://codefresh.wordpress.com/2011/10/22/log-out-link-in-joomla/ . 请参阅此链接http://codefresh.wordpress.com/2011/10/22/log-out-link-in-joomla/ you get the url to logout the current user. 你得到注销当前用户的网址。

With Joomla 2.5 you need to make a new menu item titled Logout and choose the menu type to be the User Manager - Login Form. 使用Joomla 2.5,您需要创建一个名为Logout的新菜单项,并选择菜单类型为User Manager - Login Form。

By doing this if the user is logged in then this will take them to a page with a logout button instead of the login form. 通过执行此操作,如果用户已登录,则会将其带到具有注销按钮而不是登录表单的页面。

Also if you set the access permissions to only display this logout menu item for registered users. 此外,如果您将访问权限设置为仅为注册用户显示此注销菜单项。

This was a very easy solution to do without any coding knkowledge. 这是一个非常简单的解决方案,没有任何编码知识。 Really there should be a menu item option for the user manager - logout. 实际上应该有一个用户管理器的菜单项选项 - 注销。

Link to a php page 链接到php页面

<a href="/link.php">Sign Out</a>

On the php page, simply end the session, then redirect to a new page. 在php页面上,只需结束会话,然后重定向到新页面。

<?php
    session_destroy();   //session is now over


    header( 'Location: http://www.yoursite.com/welcomepage.php' ) ; //relink to a page, with user logged out

?>

User is now logged out, and redirected to the welcome page 用户现已注销,并重定向到欢迎页面

使用此链接 -

http://www.domain.com/index.php?index.php?option=com_user&task=user.logout&token=<?php echo JUtility::getToken(); ?>

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

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