dongnuochen9449 2015-06-25 12:03
浏览 29
已采纳

PHP如何基于会话显示页面?

I am making a website. Most of it is available to anybody visiting the site, but a small portion of it requires you to register to view. I have set up the login with Sessions. After someone logs in, it sets this:

$_SESSION['login'] = TRUE;

In one of the exclusive pages, at the top of the code before the content, I have written

if ($_SESSION['login'] == FALSE) {
    header("loginpage.php");
}

However, if somebody is not logged in, that variable does not exist, and I end up with an error. Is there any other way to check if somebody is logged in? I would like something similar to what I already have, because I don't want to have to change everything.

  • 写回答

4条回答 默认 最新

  • donglu7816 2015-06-25 12:07
    关注
    if(!@$_SESSION['login'])
    {
      header("location: logingpage.php");
      exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部