duanjie6912 2014-04-24 21:44
浏览 34

我可以在每个页面的开头使用session_start(),即在我的网站的头文件中

I know if session is not destroyed at the end of some specific task then it will retain its values and could create problems next when you use it. But when you say destroying a session then does it mean ending the session like this

session_end()

or it means that you have to unset some specific session which u have set before by doing this.

unset($_SESSION['id'])

etc. And if i start a session at the top of every page and do not set it by $_SESSION['id'] etc then could that create problem for me. If yes then why i haven't got proper answer to this anywhere.

  • 写回答

1条回答 默认 最新

  • dongzhuo5185 2014-04-24 21:57
    关注

    Here is how you destroy a session:

    session_destroy();
    

    There is no such thing as session_end() in PHP.

    To empty a specific session variable, you generally do the following:

    $_SESSION['id'] = '';
    

    If you start a new session on top of every page using session_start it will just make sure the session is setup would it not be active for any reason (destroyed or never started).

    It's untrue that there would be no documentation, actually, the web is full with articles and tutorials on session management. I myself used the following that helped me a lot to setup my login system of my web app: https://www.owasp.org/index.php/Session_Management.

    I also suggest you have a read through all the functions that PHP specifically has to offer starting here: http://www.php.net/manual/en/features.sessions.php.

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题