What are the potential pitfalls of relying on global variables in PHP sessions for data?

Relying on global variables in PHP sessions for data can lead to security vulnerabilities and make the code harder to maintain and debug. It is recommended to use the $_SESSION superglobal array provided by PHP to store session data securely.

session_start();

// Storing data in session
$_SESSION['username'] = 'example_user';

// Retrieving data from session
$username = $_SESSION['username'];