سؤال

Looking to redirect the user of my site to the page they were trying to access when they have logged in. I am using a function to protect my pages until the user has logged in, if a user tries to access a secure page they are redirected to a "continue" page to sign in. I am trying to make it so that once the user has logged in, they will go straight back to the page they were trying to look at? Is this possible?

function protect_page() {
if (logged_in() === false) {
header('Location: continue.php');
exit();
}
}

لا يوجد حل صحيح

نصائح أخرى

This is a very frequently asked question with lots of answers. For example

Redirecting to previous page after login? PHP

I usually use a query string for the current page they are on. For example if they attempt to access a page profile which they need to be logged in for I would do:

header('Location: continue.php?goto=profile'); exit;

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top