What is the difference between using session_register() and $_SESSION in PHP, and which one is recommended for beginners?

Using session_register() is an older method of registering variables in a session, while $_SESSION is the recommended and more secure way to handle session variables in PHP. For beginners, it is recommended to use $_SESSION as it is more widely supported and follows best practices for session management in PHP.

// Using $_SESSION to store and access session variables
session_start();

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

// Access the variable from the session
echo $_SESSION['username'];