Are there alternative methods, besides using the header function, to pass variables between PHP files?

When passing variables between PHP files, besides using the header function, you can also use sessions, cookies, or query strings. Sessions allow you to store and access variables across multiple pages for a single user session. Cookies can store variables on the user's browser for a longer period. Query strings can pass variables through the URL.

// Using sessions to pass variables between PHP files
// File 1: store variable in session
session_start();
$_SESSION['variable_name'] = 'value';

// File 2: retrieve variable from session
session_start();
$variable = $_SESSION['variable_name'];
echo $variable;