We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

New Extensions - User Login / Logout Redirection!

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi there,

Well I had seen a lot of posts on the forum about people wanting to be able to re-direct users upon logging out of the system to a page of their choosing so thought I would take the dark plunge into writing my first extensions.

Attached is V1.1 of the Logout Redirect extension and also V1.1 of the Login Redirect extension. These are very very simple and at the moment has just the one extension setting where you can provide a URL that you would like a user to be re-directed to upon successful log-in or log-out depending on which extension you are using.

You should be able to use both extensions at the same time as they shouldn’t conflict with one another as far as I know.

I hope to improve these extensions so that they could somehow be created as plugins instead so that people would be able to set the URL in there instead of the extension settings so that you could have endless redirect paths if you so desired. That’s a bit above my head for now though so I am submitting these as they are.

I hope that I have done the right thing in posting this here like this. If I haven’t then please (moderators) don’t hesitate to slap my hands or whatever as I have never done this before so any help with the correct procedure will be appreciated.

Also if maybe one of the EE admin crew could possibly look these over and make sure that it adheres to the EE coding guide-lines and that they aren’t going to cause any damage anywhere then that would also be massively appreciated.

DISCLAIMER - Please use these extension at your own risk for now as they have not been checked by anyone other than myself

Best wishes,

Mark

Installation Instructions Download the preferred extension file from the bottom of this post. Un-zip it and follow the same directory structure as the download to place the files into their correct locations inside your EE system. Goto your Extensions Manager in the EE admin panel and enable extensions (if they are not already enabled). Next enable the Login Redirect or Logout Redirect extension (both if you wish!!). Click on the settings link for each extension that you have installed and fill in the URL to redirect to. That’s it!! 😊 ExpressionEngine Extension Installation Documentation
As pointed out to my hair brained self there is actually already a return parameter in the login form so you can pretty much do away with the Login Redirect extension as it probably won’t be needed by anyone after-all but hopefully the Logout Redirect extension should come in handy as that was the extension that I first made due to people needing this functionality which at the moment (I do stand to be corrected on this one though) doesn’t exist.

Mod Edit: Attachments removed. Please review the license.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Oops. I feel very very naughty now!!

I meant to say a massive massive thank you to Brian M and Dry over at this post for all their help in getting this to work.

Thanks a lot guys!! 😊

Best wishes,

Mark

       
Brian M.'s avatar
Brian M.
529 posts
18 years ago
Brian M.'s avatar Brian M.

Hi Mark - I’ve got a feature request (good idea for an extension btw). I’d love to be able to just send the person back to the page they were on when they logged out. Maybe if you don’t fill in the logout field in settings it does this by default? I think you could use $SESS->tracker to get this working pretty easily.

Just a thought - great first extension!

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen
EDIT : UPDATED EXTENSION IN ORIGINAL POST AT THE TOP OF THIS PAGE

Ask and ye shall receive my friend. 😊

Thanks for all the help on this one. I have now made it so that if you leave the settings field blank in the extensions settings then it will indeed take you back to the page you were just on.

I’m hoping I have the syntax correct to get the whole page as I am testing this on a DEV server and have index.php in there but hopefully this will still work with people who have taken out the index.php using .htaccess tricks?

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Also as an aside on the Sessions Page in the documentation it says that it stores five of the last visited URLs but then goes on to say that the array’s keys range from 0 to 5. is this correct as surely that would be six wouldn’t it?

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Quick update.

Was messing around and so thought I would make the companion extension to the Logout Redirect extension - the Login Redirect extension!! 😊

You can find both latest versions at the top of this thread attached to the first post.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen
UPDATE to Logout Redirect extension

I have just updated the language file for the Logout Redirect extension to inform people when they are in the settings page that leaving the field blank will send them back to the page they were just on.

Same with the Login Redirect extension. If they leave the field blank then they will just be directed to the main index page of the site.

Admittedly I think that the Logout Redirect extension is probably the better of the two as you would probably want people to be re-directed to the same place they were at upon login especially for things such as using the Simple Commerce Module so that you don’t lose your place.

I have now made the Login Redirect extension so that if you leave the settings field blank it will also take you back to the page you were recently at. I hope that I have made this in the correct way though as all I am doing is traversing through the $SESS->tracker array to return the page before the login form although I am now thinking that some people may have different login procedures that may mess this up. I will see how to get around this.

Updated files at top of thread.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Another quick update. The Login Redirect extension may not be working correctly if you are on the main index page of your site as I am testing this on a DEV server and I think that I might be spitting out the wrong URL if there is none specified in the extension settings.

The extension (Login Redirect) will hopefully work fine for all other pages on the system though. I will look into a way around this.

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Victor,

The Logout Redirect extension allows you to have the usual :

< a href= " {path=LOGOUT} " >Logout < /a>

links in your templates and when they are clicked you will be re-directed to a URL of your choosing or if the setting field is left blank then you should (hopefully) be returned back to the page that you were previously on.

The Login Redirect extension allows you to specify a URL that a user will be taken to upon successful login from the standard ExpressionEngine login form. If it’s setting is left blank then you should also be sent back to the same page that you were originally on.

as far as I know I always could do redirect on logout/login in the frontend

I don’t think that this is possible at the moment with the standard {path=LOGOUT} although would love to be proven wrong. Admittedly now I look into the login form tag I can see that there is the return=”site/contact” parameter so my Login Redirect extension probably is a bit useless!! :-(

Ah well it was the Logout Redirect extension which was the first one that I created and that people had been asking for so hopefully that one is still of some use? I just made the other one whilst I was at it as it were! Didn’t even occur to me about the return parameter as I was enjoying making my first extensions too much!! 😊

Hope that helps.

Best wishes,

Mark

       
Brian M.'s avatar
Brian M.
529 posts
18 years ago
Brian M.'s avatar Brian M.

If you leave the settings field blank it will return you to the current page - that was my feature request too 😉

Actually Mark - I think the login-redirect extension still has value. Maybe sites allow you to log in on any page and so being able to come back to the current page you logged in from has definite worth.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Brian / Victor,

Glad you like it Brian. Victor I am looking into turning this into a plug-in instead of an extension and hope to be able to let you do something like below :

{exp:logout_redirect url="http://www.yahoo.com" extras="class='logout-link' rel='logout'"}
Logout Link
{/exp:logout_redirect}

That would then turn the ‘Logout Link’ text into a click-able link that would allow you to log the person out and then re-direct them to the url specified in the plug-in parameter.

Having a bit of a problem with that one though at the moment and hoping that someone can help out with the post I have in the plugin forum.

Will keep you updated on all of this though.

Victor when you say you want to insert $current_url do you mean you want to put this into the extensions settings field? If all you want is to re-direct to the page you are on before you click on the logout link then if you leave the field blank then it will do the same thing for you. Is that what you meant or something else?

Best wishes,

Mark

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hi Victor,

Good idea. I might go with doing it that way instead. Probably would be better in that way. Still having problems figuring out how to get the plugin to do this anyway but hopefully soon!! 😊

Best wishes,

Mark

       
stinhambo's avatar
stinhambo
1,268 posts
18 years ago
stinhambo's avatar stinhambo

Thanks Mark!

What situations might someone want to be redirected to another screen?

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Hmmm now there’s the question!! 😊

On logout you may want to take someone to an (I know very 80’s) advert about your site or some page that helps to draw them back again at a later date, a sort of last minute attention grabber as it were.

This was actually made in answer to someone else’s request for this functionality so maybe they could best answer this?

I’m just a little chuffed that I have successfully (so far) made my very first extension!! 😊

Best wishes,

Mark

P.S. To anyone who may use this extension there may be a slight problem with the Logout extension if you log out from your main index page. I am currently looking into this.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
18 years ago
Mark Bowen's avatar Mark Bowen

Aha!!! I have at you now!!!

Just noticed a good thing that the Login Redirect extension does!!!

When you login using the login form you don’t get the interim “You are now logged in” page and then get the re-direct to the page you were on. Whilst some might like seeing this page to show that the user is now logged-in myself personally I don’t like seeing it and as on nearly all sites where a person can login I have usually got something on the site which will indicate to them that they are logged in anyway so this pretty much does away with the need to style one member template at least! 😊

Just thought this might swing it for some people to use this!

Best wishes,

Mark

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.