Checking session data

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:


    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.


Next chapter: Files vs. Databases >>

Previous chapter: Ending a session

Jump to:


Home: Table of Contents

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar