1
I would like to know how to create a session of the last accessed url, why this:
I have a login system on the site that if the person clicks to buy the product and is not logged in, it is directed to the login page, after logging in, it is redirected to the home with a redirect: redirect('/user/painel');
But I need that after she logs in, she goes back to the last URL accessed so she can buy the product she clicked on.
Or maybe some Location header that goes back two pages.
Note: The framework I’m using is Codeigniter
I tried to use too: header("Location: " . $_SERVER['HTTP_REFERER'] . "");
but it only goes back one page, I need it to go back two.
Doesn’t that solve? $_SESSION['ultimaUrl'] = $_SERVER['REQUEST_URI'];
– user41722
Not really, because the last url accessed is the login page.. actually need to go back to the second previous url, example: product clicking/login/login page - need to go back to product clicking not to login page
– Maurício Krüger
I think using Eduardo’s idea would be in the login page you check if there is something in this
ultimaUrl
and then when the user clicks on you or sends it to youruser/painel
or you send it to that last url.– Marcelo Diniz
If the application is like this, there should not be redirect to the home, but to the page that "requested" the login. One of the simplest ways is to pass the return to the URL.
http://paginadelogin.php?retorno=/produto012.php
- If the return is blank (or contains invalid characters and/or does not start with a bar which may indicate a forged redirect), redirect to home, or redirect to return.– Bacco
Is that what happens, I have several products, and in the internal of each has the buy button, if the person is not logged in and click buy, it is directed to the login page, making the login it is directed to the home of the site, only that I wanted instead of her going back home, she goes back to the page where she was, that is, two previous pages, because the previous page is the login form: product internal / login page / logged in. if I give a Location to go back to the last page, it ends up falling on the login page.
– Maurício Krüger
So I think it’s going to be a harder solution simpler than the one I posted in the previous comment...
– Bacco