douliandan7340 2012-12-13 18:01
浏览 45
已采纳

会话变量与正常变量? [关闭]

What's the difference? I know that session variables store information and let you use it across pages, but I've got a few questions: Where is the value stored? And what is the difference between a session variable and a normal variable?

This is in the context of PHP. I'm after an in-depth answer because I've not found alot of information about this online.

  • 写回答

3条回答 默认 最新

  • doushui3061 2012-12-13 18:12
    关注

    Where is the value stored?

    That depends on the PHP configuration. By default, session variables are serialized and written into a file on the server's file system. On each page view that starts the session, they are unserialized and accessible from the $_SESSION array. It's possible to override the default session handler so that you can store the variables elsewhere, such as a database.

    Sessions work by storing a session ID (which is a unique identifier) as a cookie on the client's computer. Each time the client requests a page, the session ID cookie is sent along with the request, PHP picks up the session ID from the cookie, and then pulls the sesssion data that relates to said session ID.

    what is the difference between a session variable and a normal variable?

    Simply put, a session variable gets saved to a source (such as file system), this is how they can persist between page requests. A normal variable will only live until the execution of the script completes, it will then be destroyed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示