dtvdz911959 2017-12-05 20:56
浏览 61
已采纳

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

Email is the user session email after successfully logout there is no email exist but on index page is shows undefined index as there is no email after logout.

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'];
?>
  • 写回答

1条回答 默认 最新

  • douzuan2814 2017-12-05 21:01
    关注

    Just verify that it's set. That will probably be useful to you anyway, because I assume if it isn't set you may want to do something different.

    <?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)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?