psaw.mora
psaw.mora

Reputation: 958

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...

Upvotes: 0

Views: 828

Answers (2)

Your Common Sense
Your Common Sense

Reputation: 157839

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.

Upvotes: 0

Aurelio De Rosa
Aurelio De Rosa

Reputation: 22152

  • 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.

Upvotes: 1

Related Questions