1
votes

I am currently trying to setup a login script. I am trying to get it so when people use the login.php page it takes them back to the page they were viewing before they logged into the login.php page. For example if they were on testpage1.php then went to login.php logged in it would redirect them to testpage1.php.

So far I have followed some tutorials on SESSIONS with the following.

session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];

and on the login page I have

if(isset($_SESSION['url'])) {
    $url = $_SESSION['url']; // holds url for last page visited.
    $page->body ("$url");
}

I printed out the $url just to see the full redirect and I notice that it will only ever take it back to the login.php page rather than testpage1.php.

I know I could set a header and just forward the user to index.php or something similar but I think that would break the flow of working on the site.

Is there a way to get the redirect to go to the page before what would be captured using REQUEST_URI?

1
I think you confused somewhere. Your question is not clear. So If I got it correct you want to SAVE uri visited by user, then CHECK if user has been logged in correctly and if not redirect him to the login page , but still keep saved original uri he wanted. and once he got logged in redirect him to that page? am I right?Alex

1 Answers

0
votes

You need to put session_start(); before using $_SESSION on any page where you use it.