dpgbh20688 2015-05-03 08:00
浏览 41

无法使用php会话重定向到另一个页面

So I have this code on my login.php that when the user and password matches with the database it will redirect to another page which requires logging in first before it can be accessible.

Here is my code in login

            $_SESSION['userlog'] = true;
            header('location: table.php');

And here is my code that requires logging in before the page become accessible.

           if(empty($_SESSION['userlog']))
           {
           header('LOCATION: login.php');
           }

The problem is when I click on login, it does not redirect in the next page. Any idea what is wrong or missing in my code?

  • 写回答

1条回答 默认 最新

  • dongre9937 2015-05-03 08:10
    关注

    Did you declare session_start(); at the top of the page to enable sessions?

    I would recommend validating if it was in fact set using isset and then empty

    if(!isset($_SESSION['userlog']) && empty($_SESSION['userlog']))
    {
        header('LOCATION: login.php');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗