How to send to the last page after login?


#1

hi i do a login with slim
now after the user come in to the system how u do that the user go to the last page him come in to the login page


Get previous route and redirect after action (submitting form etc.)
#2

You could use for example session for storing last url.


#3

u can show me how plz
with example?


#4

Ofcourse you need to know how to use sessions properly, but simpy:

  • start session when bootstrapping your app: session_start();
  • when checking if user is logged in or not, save current url or route name to session
  • when user is logged in, check if session includes url or route name and if it does, then redirect to that

#5

I cheated and used flash messages to store the referrer in my example app: https://gitlab.com/Antnee/slim-skeleton-php7/blob/master/App/middleware.php#L12


#6

Flash uses sessions, so basically you did what I suggested but with some extra files and code :slight_smile:


#7

Yep. It’s an example though :slight_smile:


#8

I didn’t understand do II put that in the auth.php ?

Do you have an code example? And where do I put it?


#9

I’m not sure what you’re asking and I don’t know what’s in your auth.php and what you’re trying to do. Would need more information to help you out.