PHP会话超时差异

PHP会话超时差异,php,session,Php,Session,currentpage.php session_start(); $_SESSION['another_session']="another_session"; header("location:currentpage.php"); 案例1: session_start(); if (isset($_SESSION['one_session']) && (time() - $_SESSION['one_session'] > 180

currentpage.php

session_start();
$_SESSION['another_session']="another_session";
header("location:currentpage.php");
案例1:

session_start();
if (isset($_SESSION['one_session']) && (time() - $_SESSION['one_session'] > 1800)) {
    session_unset();     
    session_destroy();   
}
$_SESSION['one_session'] = time();

if(isset($_SESSION['another_session']))
{
 echo "another_session";
}
session_start();
if(isset($_SESSION['another_session']))
{
 echo "another_session";
}
案例2:

session_start();
if (isset($_SESSION['one_session']) && (time() - $_SESSION['one_session'] > 1800)) {
    session_unset();     
    session_destroy();   
}
$_SESSION['one_session'] = time();

if(isset($_SESSION['another_session']))
{
 echo "another_session";
}
session_start();
if(isset($_SESSION['another_session']))
{
 echo "another_session";
}
在案例2中,如果我在24分钟后刷新页面(默认超时),那么会话将无法正常工作??因此echo不会输出任何东西

但是在案例1中,会话会持续30分钟吗??如果我在24分钟后刷新页面,echo会工作吗??如果是,为什么??两种情况在会话超时方面有什么区别

编辑:假设我已在previouspage.php上设置了$\u SESSION['other\u SESSION'],然后登录到当前页面

上一页可能是这样的 previouspage.php

session_start();
$_SESSION['another_session']="another_session";
header("location:currentpage.php");
流程的详细信息:

session_start();
if (isset($_SESSION['one_session']) && (time() - $_SESSION['one_session'] > 1800)) {
    session_unset();     
    session_destroy();   
}
$_SESSION['one_session'] = time();

if(isset($_SESSION['another_session']))
{
 echo "another_session";
}
session_start();
if(isset($_SESSION['another_session']))
{
 echo "another_session";
}

首先打开previouspage.php,然后进入currentpage.php,然后等待24分钟(默认超时)并刷新currentpage.php.Now currentpage.php有两种情况,我已经在上面解释过了。现在我想知道$u会话['另一个会话']如果我在24分钟后刷新currentpage.php,它将过期?或者它将在30分钟后过期?如果输出不同,您能告诉我这两种情况的区别吗?如果输出相同(这两种情况下都意味着会话将在24分钟后过期),那么我如何将$\u session['other\u session']的超时时间增加到30分钟?

您从未设置过$\u session['other\u session'],因此产生输出的条件将永远不会发生。谢谢您的回复,但我已经设置了$\u session['other\u session']在不同的页面上。那么在不同的页面上一定有错误,或者你做事的顺序。请在你的问题中加入“另一个会话”所在的代码部分,并添加一些关于你的应用程序流程的详细信息。我已经更新了这个问题,使你能够清楚地理解它。你现在可以看一下吗?previouspage.php set
$\u session['other\u session']=“other\u session”
字符串?从最重要的环节开始练习-检查是否已设置-检查剩余时间或其他东西-玩它,这是理解和学习这一点的最佳方式。没有编码,没有真正的测试,你无法学习编码。