Welcome Guest, Not a member yet? Register   Sign In
Automatically redirect to password protected page after logging in
#1

[eluser]novice32[/eluser]
I'm new to CI, and it seems like an awesome framework.

For pages that are logged-in session/password protect, how can I automatically redirect to that page after the user logs in?

Novice
#2

[eluser]frist44[/eluser]
I had a similar thought before. I basically do a logged in check before the pages that are user-only access. I also capture the previous url in the session, by putting a post controller hook that writes the current url to the previous url session key because by the time the processing of the next function comes around, it'll still be the previous page. So you direct people to the login page, and if successful, back to the previous url in the session.

However, you have to be careful not to catch certain urls, like the login page or else it'll try to redirect back to itself. So I keep an array utility type pages/functions that I don't want captured as a user visited page.

The method has worked well so far and I don't ever have to touch it.
#3

[eluser]novice32[/eluser]
Great.. thanks for the suggestions. Sounds a little tricky to implement.

.NET uses a get parameter called "ReturnUrl" to indicate the target page after logging in. So, "Login.aspx?ReturnUrl=/Secure/Profile.aspx" would redirect the person to "/Secure/Profile.aspx" after logging in.

Thanks
Novice32
#4

[eluser]frist44[/eluser]
well that's not to say that you couldn't do the same thing and have returnUrl be url parameter like:

www.domain.com/login/returnurl/search

The only tricky thing would be if the return URL had "/"'s in it because it would interpret that as another url parameter. I did something similar and just replace "/" with another character so it was all in the same string when you pull it out into an associative array.




Theme © iAndrew 2016 - Forum software by © MyBB