简体   繁体   English

在php中的会话范围内存储数据的方式和生命周期

[英]Way of storing data in the session scope in php and the life cycle

Is there a way of storing variables in a PHP application in the session scope or the application scope...? 有没有一种方法可以在会话范围或应用程序范围内的PHP应用程序中存储变量? At the same time can someone please explain the life cycle of a php program..? 同时有人可以解释php程序的生命周期吗? Thanx... 谢谢...

  • For the application scope you can use the define function. 对于应用程序范围,可以使用define函数。
  • For the session scope you can use the $_SESSION array. 对于会话范围,可以使用$ _SESSION数组。
  • For the third question....too too broad.Anyway you can take a look to this tutorial . 对于第三个问题....太宽泛了。无论如何,您都可以看一下本教程 Just Google it. 只是谷歌。

life cycle of a php program is very short. php程序的生命周期非常短。
It's not like a desktop application constantly running in your browser, and not even a demon with persistent connection to your desktop application. 它不像桌面应用程序在浏览器中持续运行,甚至也不是与桌面应用程序保持持久连接的恶魔。 It's more like a command line utility - doing it's job and exits. 它更像是命令行实用程序-完成工作并退出。 It runs discrete: 它运行离散:

  1. a browser makes a call 浏览器拨打电话
  2. PHP wakes up, creates an HTML page, sends it to the browser and dies PHP唤醒,创建HTML页面,将其发送到浏览器并死亡
  3. Browser renders that HTML and shows it to the user. 浏览器呈现该HTML并将其显示给用户。
  4. User clicks a link 用户点击链接
  5. a browser makes a call 浏览器拨打电话
  6. another PHP instance, knowing nothing of the previous call, wakes up and so on 另一个PHP实例,不知道先前的调用,将唤醒 ,依此类推

That's why you need sessions - to save the variables between calls. 这就是为什么您需要会话-保存两次调用之间的变量的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM