duanhao8540 2014-12-19 15:00
浏览 25
已采纳

注意:未定义的索引:已记录[关闭]

Notice: Undefined index: logged

This is bizarre and I cant figure it out as I have used the session logged = true/false twice throughout my website and it works flawlessly.

I have tried using isset which just returns a blank screen

<?php 
        if($_SESSION['logged']==true)
          { 

            echo '<div class="container">
                    Logged in!
                  </div>'; 

          }
        elseif($_SESSION['logged']==false)
          {
            echo '<div class="container">
                    You must be logged in to use the events service
                  </div>';     
          }
      ?>

The session is set from another file.

if($count==1)
  {
    $_SESSION['logged']=true;
    $_SESSION['username']=$myusername;
    header("Location: ../index.php");
    exit();
  }
else
  {
    $_SESSION['logged']=false; 
      header("Location: loginError");
    exit();
  }

The thing I cannot figure out is why the error message is displaying when i'm using it this time and not the other 2 times? as the if and else statement is actually working fine if you ignore the error message!

The previous 2 times I use this session logged I also have no error messages displayed and it works fine.

  • 写回答

1条回答 默认 最新

  • duanbianweng5353 2014-12-19 15:03
    关注
          session_start();
          if(isset($_SESSION['logged']) && $_SESSION['logged']==true)
          { 
    
            echo '<div class="container">
                    Logged in!
                  </div>'; 
    
          }
          else //else no session was set or it was not true
          {
            echo '<div class="container">
                    You must be logged in to use the events service
                  </div>';     
          }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致