How can sessions be used to store and pass variables in PHP, and what are the advantages of this method?

Sessions in PHP can be used to store and pass variables between pages or requests. This is done by starting a session with `session_start()` and then setting variables in the `$_SESSION` superglobal array. These variables can then be accessed on subsequent pages as long as the session is active. The advantages of using sessions for variable storage include security (as the data is stored on the server), persistence (variables are available across multiple requests), and convenience (easy to set and retrieve variables).

// Start the session
session_start();

// Set a variable in the session
$_SESSION['username'] = 'john_doe';

// Access the variable on another page
echo $_SESSION['username'];