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

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)