Changes

Jump to: navigation, search

Understanding PHP Sessions

599 bytes added, 17:06, 6 June 2007
Creating PHP Session Variables
</pre>
== Creating and Reading PHP Session Variables ==
Variables can be assigned to a session using the $_SESSION array. This is a global array that is accessible to all the pages on your web site. The is also an associative array (see [[PHP Arrays]] for details of using arrays in PHP) and as such it is possible to access array elements using the variable name as an index. 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 and variable name: <pre><?php $_SESSION['userName'] = 'JohnW';?></pre> Another option is to use the PHP ''session_register()'' function. ''session_register()'' takes two arguments, the string represnting the variable name, andthe value to be assigned to the variable: <pre><?phpsession_register('username', 'JohnW');?></pre>

Navigation menu