我有4个文件home.php, log_out.php, blank_one.php, connection.php并且不包括login.php和index.php,因为它只读取用户名和密码
我的问题是点击退出后的会话
然后按箭头返回
直接进入blank_one.php我得到这些错误:'(
-
注意:未定义索引:CurrentUser
-
注意:未定义索引:CurrentUserType
- 空白一个
========================================================================
和由于登出(log_out.php)被点击的内容必须是没有用户找到,空和返回应该被禁用。
是否有一种方法来处理这个会话,以消除错误后销毁它?
'请帮助。:"(
blank_one.php
<?php
session_start();
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
echo('BLANK ONE');
?>
home。
<?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>';
}
?>
connection.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中也需要这样做
您应该测试会话变量(与登录页面一起创建)是否设置为验证用户是否登录。
blank_one.php
<?php
session_start();
if( (isset($_SESSION['CurrentUser']) &&(isset($_SESSION['CurrentUserType'])) {
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
}
else {
echo('BLANK ONE');
}
?>
在受保护的页面中也应该这样做,以避免在用户未登录时直接访问URL的错误和安全问题。在这种情况下,用户应该被重定向。
home。
<?php
session_start();
if( (isset($_SESSION['CurrentUser']) &&(isset($_SESSION['CurrentUserType'])) {
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
}
else
{
header('Location:index.php');
die();
}
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>';
}
?>