10.3.6 Checking session dataThis is NOT the latest copy of this book; click here for the latest version.
You can check whether a variable has been set in a user's session using the function isset(), as you would a normal variable. Because the $_SESSION superglobal is only initialised once session_start() has been called, you need to call session_start() before using isset() on a session variable. For example:
<?php
session_start();
if (isset($_SESSION['FirstName'])) {
/// your code here
} ?>
You can, of course, also use the empty() function with session data, or indeed any other function - the $_SESSION array and its data can be used like any other array.
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|