douyi3632 2010-01-29 21:44
浏览 39
已采纳

关于用户系统的问题,特别是与PHP的会话

I was reading this article: http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/2/

I am not sure if I understand sessions properly. Do I have to start a session for each member protected page? or do I just have to create one session and check if the user is in a session on each and evey page? how would I do that? Examples apprecited! :)

  • 写回答

1条回答 默认 最新

  • dongshuxi3105 2010-01-29 21:47
    关注

    you (usally) don't really create a session. You just session_start(); on beginning of EVERY page and assign data to $_SESSION.

    EDIT:

    PHP sessions are not really "sessions", they're just containers of data.

    When users logs in, you assign to session for example:

    $_SESSION['loggedin'] = '1';

    And on every page you check that:

    if($_SESSION['loggedin'] !== '1')
    {
       exit;
    }
    
    // your stuff
    

    very simple.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题