简体   繁体   English

检查会话是否过期,然后重定向(Joomla)

[英]Check if session is expired, then redirect (Joomla)

what I am trying to do is so simple but I can't find a clue on how to make it happen. 我想做的事情很简单,但是我找不到如何实现它的线索。

I have a huge form that is made of several php files and these files being called using AJAX that user has to fill, what exactly I want to achieve is: 我有一个巨大的表格,它由几个php文件组成,这些文件是使用用户必须填写的AJAX来调用的,我要实现的正是:

1) test if session has expired on every page of this form. 1)测试会话是否在此表单的每个页面上到期。

2) if session is expired, I want to redirect him to a specific URL, let's say http://www.example.com 2)如果会话已过期,我想将他重定向到特定的URL,例如http://www.example.com

Thanks in advance for your help. 在此先感谢您的帮助。 Regards. 问候。

You can check if the session is active by using 您可以通过使用以下命令检查会话是否处于活动状态

$session = JFactory::getSession();

if ($session->isActive()) {
}

First thing that comes to my mind is to check if session cookie exists. 我想到的第一件事是检查会话cookie是否存在。 If session is active then by default PHP session mechanism uses cookie with default name 'PHPSESSID'. 如果会话是活动的,则默认情况下,PHP会话机制使用默认名称为“ PHPSESSID”的cookie。 So if cookie PHPSESSID exists, your session is active. 因此,如果存在cookie PHPSESSID,则您的会话处于活动状态。

You can check if session cookie exists like this: 您可以像这样检查会话cookie是否存在:

if(isset($_COOKIE['PHPSESSID'])) {
    echo 'Session is active!';
} else {
    echo 'Session is not active!';
}

To redirect you can use this: 要重定向,您可以使用以下命令:

header('Location: http://example.com');

And to check for session cookie name use this: 要检查会话cookie名称,请使用以下命令:

session_start();
echo 'Session cookie name is: ' . session_name();

By default its 'PHPSESSID', but you or server admin could change that so check it out! 默认情况下,其为“ PHPSESSID”,但您或服务器管理员可以更改此设置,因此请检查!

Hope this helps! 希望这可以帮助!

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

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