How can default values be properly set and passed to the next page in PHP when session variables are empty or not set?

When session variables are empty or not set, default values can be properly set and passed to the next page by checking if the session variables are empty or not set. If they are empty or not set, then assign default values to them before passing them to the next page.

// Check if session variables are empty or not set, then assign default values
$variable1 = isset($_SESSION['variable1']) ? $_SESSION['variable1'] : 'default_value1';
$variable2 = isset($_SESSION['variable2']) ? $_SESSION['variable2'] : 'default_value2';

// Pass the variables to the next page
$_SESSION['variable1'] = $variable1;
$_SESSION['variable2'] = $variable2;