PHP Coding Tips

Monday, August 20, 2012

PHP Store variable in a session

As you propably know, HTTP protocol is stateless, that means that each request run php parser and doesn't know about variables from previous page displayed.You can mantain variable values betweend numerous requests of the same user by storing this varaibles in session. To do that, you just have to call session_start() to start a session (a ID of session will be stored in browser cookies) and add a variable to $_SESSION array.See example below:session_start(); $_SESSION['myvalue'] = 5; Now, if you get $_SESSION['myvalue'] on other user request, you will get value of 5.

No comments:

Post a Comment