
Notice that we change the value after the variable has been registered. We could also do the
opposite—set the value and then register the variable. The final value of the variable on the
page is the one that will be available on subsequent pages. At the end of the script, the session
variable is serialized, or frozen, until it is reloaded via the next call to session_start().
We therefore begin the next script by calling session_start(). This script is shown in
Listing 20.2.
LISTING 20.2 page2.php—Accessing a Session Variable and Deregistering It
<?
session_start();
echo “The content of \$sess_var is $sess_var<br>”;
session_unregister(“sess_var”);
?>
<a href = “page3.php”>Next page</a>
After calling session_start(), the variable $sess_var is available with its previously stored
value, as you can see in Figure 20.2.
Advanced PHP Techniques
P
ART IV
436
FIGURE 20.2
The value of the session variable has been passed along via the session ID to page2.php.
After using the variable, we call session_unregister() to deregister the variable. This way,
the session still exists, but the variable $sess_var is no longer a registered variable.
Finally we pass along to page3.php, the final script in our example. The code for this script is
shown in Listing 20.3.
25 7842 CH20 3/6/01 3:42 PM Page 436
Comentarios a estos manuales