How to Start a Session?

How to Start a Session?

Before you can store any information in session variables, you must first start up the session. To begin a new session, simply call the PHP session_start() function. It will create a new session and generate a unique session ID for the user.

Where do I put session start?

You want to put session_start(); at the top of your page before any other code. However, if you are using includes to make your life easier, it's best to put it at the very top of a file that is included in all files.

When should I start a session?

you can start session once user is authenticated. after that you can user related information in S_SESSION and access this info from anywhere. You should start session after verifying user's information, and than you can set user's uid to session variable.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.