Session with PHP
The premise of a session is that data is stored on the server, not in the Web browser and a Session identifier is used to locate a particular user's record (session data).
ex.: session_start(); $_SESSION['first_name'] = $row[1]; $_SESSION['name'] = 'Jessica';
ex.: session_start(); $name = 'Jessica'; session_register('name'); $first_name = $row[1]; session_register('first_name'); Session_Start()
Accessing Session Variables syntax: $_SESSION[' variable name '] $HTTP_SESSION_VARS ex.: session_start(); IF ( !isset($_SESSION['first_name'])) { Header("location: http://" . $_SERVER['HTTP_SELF'] . dirname($_SERVER['PHP_SELF']) . "/index.php"); exit(); } $page_title = 'Logged In'; include ('top/header.inc'); . . . . . . . . . Delete Session Variables The following are to be use for removing or deleting an existing Session variable(s) and as follows: syntax: unset() for single variable use only. ex.: unset( $_SESSION[' var '] ); array() reset the whole Session array by assign'n an Empty array. ex.: $_SESSION = array(); session_destroy() remove all task from the server side Changing the Session Behavior syntax: init_set( parameter, new_setting ); ex.: init_set( 'session.save_path', '/path/to/folder');
session_name ('var'); ex.: session_name ('YourVisitID');
ex.: session_name ('myvisitID'); session_start(); . . . . . . . ... Garbage Collection Note: session_gc_maxlifetime = 1,440 session_gc_probability = 30 controls the frequency of how temporary data will be removed from the system when not in use any more or when not needed at all. Accessing Arrayed Session Variables ex.: session_start(); if (!is_array($_SESSION['sesCart'])) { $_SESSION['sesCart'] = array(); } $intFlgUnique = 1; for ($intCtr=0; $intCtr < count($_SESSION['sesCart']); $intCtr++) { if ($_SESSION['sesCart'][$intCtr]["id_itm"] == $intItmID) { $intFlgUnique = 0; } } |

