public static function expired()
{
if (isset($_SESSION['logged_id']))
{
if (time() - $_SESSION['time'] > 3600)
{
header('Location: http://nostools.cz/scripts/logout.php');
$_SESSION['last_visited'] = $_SERVER['REQUEST_URI'];
} else {
$_SESSION['time'] = time();
return true;
}
}
}
public function logout()
{
$onlinedestroy = Query::getInstance()->delete('online', array('user_id', '=', $_SESSION['logged_id']));
unset($_SESSION['logged_id']);
$this->redirect("http://nostools.cz/content/login/");
}
此脚本位于每个页面上。在$ _SESSION [' last_visited']是logout.php,我需要获取上一页,我也尝试使用$ _SERVER [' HTTP_REFERER']。 有人可以告诉我如何获得上一页吗?
答案 0 :(得分:1)
你可以在会话中存储url,$ _SESSION ['visited_page']在标题内。每次用户访问不同的URL时,此会话值都会更新。在注销期间,您可以将$ _SESSION ['visited_page']内的网址分配给$ _SESSION ['last_visited']并取消设置$ _SESSION ['visited_page']。现在你有url用户上次访问。我希望你明白我的观点。
答案 1 :(得分:0)
在注销功能中重定向时,您可以检查last_visited
变量。将其添加到您重定向的网址,如下所示:
$this->redirect("http://nostools.cz/content/login?last_visited=" . $last_visited );
然后当您登录时检查是否设置了$_GET['last_visited']
,如果是,那么您将从登录名重定向到该页面
答案 2 :(得分:0)
您应首先使用$ _SERVER ['HTTP_REFERER']在变量中获取用户引用页面;在您的登录页面。
LIKE:
<?php
session_start();
$refPage = $_SERVER['HTTP_REFERER'];
?>
现在,当用户点击“登录”时,将标题位置更改为用户参考页面
LIKE:
<?php
if(isset($_POST[login])){
session_start();
header('location:' . $refPage);
}
?>
在这段时间你应首先检查用户是否将页面空白,因为你的用户可以直接访问你的登录页面,然后你的$ refPage变量将为空,所以点击登录页面后就会停留在这里
LIKE:
<?php
if(isset($_POST[login])){
session_start();
$refPage = $_SERVER['HTTP_REFERER']; // get reffer page url
if(empty($refPage)){
header('location: yourredirectpage'); // if ref page is empty then set default redirect page.
}else{
header('location:' . $refPage); // or if ref page in not empty then redirect page to reffer page
}
}
?>
或者您可以使用隐藏的输入类型,您可以设置值$ _SERVER ['HTTP_REFERER'];
LIKE:
“&GT; 当用户单击Login时,您可以获取refPage值并重定向上一页。你还应该检查空的参考页面。因为您的用户可以直接访问您的登录页面。
谢谢。