There are different way to run PHP code. For example user initiate reloads and user initiated ajax requests.
What it the best way to maintain state between these runs?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP does consider it separate runs. Two things:
The session id will be the same across all page views for that particular user, so creating a new session() in the second snippet will still refer to the same session you started in the first snippet.
Here’s what a static implementation might look like:
That should really be all you need. There are certainly many ways to do this, but this ought to get you started 🙂