Sessions

Session mechanism allows the passing of parameters between pages easily. The variables are stored on the server side and the client kept only the session ID browse around this website. This ID is stored in a cookie or passed through the URL. PHP is able to identify himself or the client computer is turned on cookie mechanism and, if necessary, add a session ID to each URLu and form.

However, this requires having PHP compiled with –enable-trans-sid.
As the session may be based on cookies, also in this case prior to the start of the session to review may not be sent to any other data.
Upon receipt of the client request PHP automatically (if PHP configuration option is enabled auto_start) or „manually” by the programmer (using the session_start ()) checks if already assigned session ID. If so, PHP reads the variables registered in this session. If not, it generates a new unique session ID.
PHP began to track the value of a variable, you must first register it using session_register (varname). There is also a reverse version of this function – the function session_unregister (varname) makes PHP „forget” about this variable.
In PHP 4.1.0 introduced have been described previously superglobals. One of these variables, $ _SESSION stores variables registered in the session. The key of this table is of course the name of the registered variable.

This table, however, has a certain difference compared to other arrays superglobal. Namely, you can use it to record the session variables. Just assign a value to the appropriate key of the array to a variable has been registered.
Example
<?php

session_start ();       // Can be omitted if you are sure that it is enabled auto_start

if (!isset ($_ SESSION [‚count’])) {                         // if the variable is not registered
$ _SESSION[‚Count’] = 0;                              // Assign its initial value
} else {                                                                           // if it is registered
$_SESSION [‚Count’] ++;                                        // Increase its value
}

echo ‚page read’. $_ SESSION [‚count’]. ‚times during this session’;

?>

 

The script in this example will remember the number of visits throughout the life of the browser, if the browser is turned on cookies, or until the page is refreshed with the same number of sessions submitted by the URL.
Using a session raises some doubts: what if someone steals’ session number? In this way, you gain access to data stored in the session. Although there is a theoretical possibility, the number of available session IDs is so large that such theft ‚would be entirely coincidental

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close