session_start();
$_SESSION['myvalue'] = 5;
Now, if you get $_SESSION['myvalue'] on other user request, you will get value of 5.
PHP Coding tips & tricks. Function & error explanation, coding style, how tos etc. Short notes posted directly from developer work environment.
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:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment