简体   繁体   中英

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...? At the same time can someone please explain the life cycle of a php program..? Thanx...

  • For the application scope you can use the define function.
  • For the session scope you can use the $_SESSION array.
  • 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.
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
  3. Browser renders that HTML and shows it to the user.
  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

That's why you need sessions - to save the variables between calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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