Changes

Jump to: navigation, search

Understanding PHP Sessions

34 bytes added, 17:38, 13 May 2009
no edit summary
== Creating a PHP Session ==
PHP sessions are created using the ''session_start()'' function which should the first function call of the PHP script on your web page (i.e . before any output is written to the output stream).
The following example demonstrates the creation of a PHP session:
Session variables can be any type of data such as strings, numbers, arrays and objects.
Session variables can be defined using a number of mechanisms. Variables can be assigned directly to the $_SESSION array using the assignment operating operator and variable name:
<pre>
== 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 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:
</head>
</pre>
 
<google>BUY_PHP_BOTTOM</google>

Navigation menu