Changes

Jump to: navigation, search

Understanding PHP Sessions

176 bytes added, 18:11, 6 June 2007
Writing PHP Session Data to a File
== Writing PHP Session Data to a File ==
Session data only stays active on the web server until it expires or the session is deleted. Once deleted, all the data associated wiht with the session is lost. A snapshot of the session data can , however, be taken at any time and written out to a file. Once saved it can be reloaded when required.
To save a session state the ''session_encode()'' function is used combined the PHP file I/O functions (see [[PHP, Filesystems and File I/O]] for details of reading and writing files). The ''session_encode()'' function returns an encoded string containing the session data. Once this string has been obtained it can be written to a file:
</pre>
If you are interested in seeing what the encoded session data looks like you can load it into a text editor. The above example creates the following data in the file:
<tt>userName|s:5:"JohnW";emailAddress|s:16:"[email protected]";</tt><br>
== Reading a Saved PHP Session ==

Navigation menu