我有 4 个文件 home.php、log_out.php、blank_one.php、connection.php 并且不包括login.php和index.php,因为它只读取 用户名和密码。
我的问题是单击注销后的 session
then click arrow back
直接去blank_one.php我得到这些错误:'(
注意:未定义索引:CurrentUser
注意:未定义索引:CurrentUserType
- 空白
================================================== =========================
并且由于单击了注销(log_out.php),因此内容必须是未找到用户,应禁用EMPTY和返回。
有没有办法处理这个 session ,以在销毁它后消除错误?
`请帮忙。 :'(
blank_one.php
<?php
session_start();
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
echo('BLANK ONE');
?>
home.php
<?php
session_start();
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
if($currUserType == '1' or $currUserType == '2')
{
echo '
<html>
<body>
<a href="blank_one.php">blank</a>
<a href="log_out.php">logout</a>
</body>
</html>
';
}
else if($currUserType == '2'){
}
else if($currUserType == '3'){
echo '
';
}else{
echo '<div> no user found </div>';
}
?>
连接.php
<?php
$conn = mysql_connect('localhost', 'root', '', 'life');
if (!$conn)
{
die('Connect Error: ' . mysql_errno());
session_destroy();
session_start();
}
else
{
//echo ("connected from connection.php");
session_start();
echo ("");
}
?>
log_out.php
<?php
session_start();
include('connection.php');
$conn = mysql_connect('localhost', 'root', '', 'wildlife');
if ($conn)
{
$update=mysql_query("INSERT INTO wrd_user(emp_log_out) VALUES (now())");
session_destroy();
mysql_close();
header('Location:index.php');
}
else
{
echo ("");
}
?>
最佳答案
将变量设置代码包装在blank_one.php中即可解决问题:
<?php
session_start();
if (isset($_SESSION["CurrentUser"])) {
$currUser = $_SESSION["CurrentUser"];
}
if (isset($_SESSION["CurrentUserType"])) {
$currUserType = $_SESSION["CurrentUserType"];
}
echo('BLANK ONE');
?>
您在 home.php 中也需要相同的内容。
关于php - 登录时销毁 session 并禁用返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39351179/