How can variables be passed from one PHP file to another using the header function?
To pass variables from one PHP file to another using the header function, you can set the variables as URL parameters and then redirect to the second PHP file using the header function. In the second PHP file, you can retrieve the variables from the URL using the $_GET superglobal array.
// First PHP file (file1.php)
$variable1 = 'value1';
$variable2 = 'value2';
header("Location: file2.php?var1=$variable1&var2=$variable2");
exit;
// Second PHP file (file2.php)
$var1 = $_GET['var1'];
$var2 = $_GET['var2'];
echo $var1; // Output: value1
echo $var2; // Output: value2