PHP redirecting to a page defined as a $_SESSION variable [closed]

I am implementing a user authentication scheme in my webapp and I was wondering what the best approach was to redirect a user to their intended page after they successfully logged in.

For example, a user connects to a timesheet.php page, but becasue they have not logged in beforehand the are redirected to the login page. Once they successfully log in, I would like to redirect the user to their originally intended page (timesheet.php).

I have tried creating a session variable ($_SESSIOn[‘redirect’] = ‘timesheet.php’;) and after logging in if the $_SESSION[‘redirect’] isset, execute header(Location: $_SESSION[‘redirect’];, but that does not work.

Am I doing something wrong, or is this not a supported approach with the header() function?

On detection that not logged in…

$_SESSION['redirect'] = "timesheet.php"; header('Location: login.php'); exit();

Inside login.php…

On successful password_verify()…
header(Location: $_SESSION['redirect']);