PHP: 用户注销成功但注销刷新主页后显示未定义的变量:

PHP: user is successfully logout but after logout refresh home page it shows that undefined variable:

邮箱是注销成功后的用户会话邮箱,没有邮箱存在,但是在索引页面上显示未定义的索引,因为注销后没有邮箱。

Notice: Undefined index: email in C:\xampp\htdocs\CMS\index.php on line 9
    <?session_start();
?>
<?php
    require("conection/connect.php");   
    $username=$_SESSION['email'];
    $sel= "select * from users where email= '$username'";
    $run_name = mysqli_query($con, $sel);
    $row_user=mysqli_fetch_array($run_name);
    $name=$row_user['name'];
    $userid=$row_user['user_id'];
    $teacherid=$row_user['teacher_id'];
    $userid=$row_user['stu_id'];
    $usertype=$row_user['type'];
?>

verify that it's set。无论如何,这可能对您有用,因为我假设如果 不是 设置,您可能想做一些不同的事情。

<?php

if (!isset($_SESSION['email'])) {
    // maybe redirect to login?
    // or at least don't show them logged-in user type stuff
}

// your code (in an else block if you didn't redirect in the if)