Php 如何在未登录或注销后停止移动到中间页面?
我试图在条件满足时创建会话。会话将从index.php页面启动,当条件满足时,它将转到event.php页面,在event.php中,我已注销了logout.php,它破坏了会话并将页面移回index.php页面 我的问题是,每当我尝试直接访问event.php页面而不通过index.php时,我都可以这样做。即使在注销后,我也可以访问page event.php页面 My code index.phpPhp 如何在未登录或注销后停止移动到中间页面?,php,session,Php,Session,我试图在条件满足时创建会话。会话将从index.php页面启动,当条件满足时,它将转到event.php页面,在event.php中,我已注销了logout.php,它破坏了会话并将页面移回index.php页面 我的问题是,每当我尝试直接访问event.php页面而不通过index.php时,我都可以这样做。即使在注销后,我也可以访问page event.php页面 My code index.php if(condition==true){ session_start(); header(
if(condition==true){
session_start();
header("location:event.php");
}
在event.php中
session_start();
if (session_id()!=null){
load page
}
else{
move to index.php
}
在logout.php中
session_start();
session_unset();
session_destroy();
header("location:index.php");
在index.php中,将会话变量初始化为$\u session[var]=value 然后在event.php中检查
if (isset($_SESSION[var])){
load page
}
else{
move to index.php
}
在获取数据数组的登录时,将其保存在会话变量中,如
$_SESSION['user'] = 'your_array_with_user_data';
现在,请检查start like中的每一页
if(!isset($_SESSION['user'])){
//redirect code
}
else{
//page code
}
然后像下面这样破坏会话
session_destroy();
或
如何通过session_start()函数启动session。是吗?先生。。为会话命名,如$_会话['user']='Your_array'是的,它正在工作。谢谢。我正在将event.php中的session_id()与null进行比较,并且在注销时销毁会话。您能告诉我它有什么问题吗?可能是使用命令“header”(“location:index.php”);”您可以转到index.php并在那里启动一个新会话。如果您想要登录和注销,您可能应该在event.php中使用[index,event,logout]->[login,index,event,logout],而不是[index,event,logout],您应该在会话开始之前使用一个条件。如果没有条件,您可以随时转到event.php并启动会话,或者在销毁事件之前,只需取消会话即可,因为我以某种方式管理了它。在index.php中创建了$_会话['somevar']='val',在event.php中检查它,并在logout.php中销毁它。现在它正在工作。仍然可以在不登录的情况下移动到event.php。在index.php中创建一个会话变量,并在event.php中检查它
session_destroy();
session_unset();