I need a "redirect after log in" code Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
+3
Ange Tuteur
Take Notes
OMMA
7 posters

    I need a "redirect after log in" code

    OMMA
    OMMA
    Forumember


    Male Posts : 59
    Reputation : 1
    Language : English
    Location : USA

    Solved I need a "redirect after log in" code

    Post by OMMA February 5th 2016, 8:15 pm

    Is there a java code or a template edit that I can use to redirects members to a certain page after they log in? What I mean is if a person is reading a certain thread as a guest and decides they want to post, they log in and are redirected to that thread so they can post. As of now when they log in they are redirected to the index. This means they have to click their way back to the thread they wanted to post in. I would like people to be redirected to the last page they were viewing once they log in.
    Take Notes
    Take Notes
    Helper
    Helper


    Male Posts : 2337
    Reputation : 324
    Language : English
    Location : Forumountain

    Solved Re: I need a "redirect after log in" code

    Post by Take Notes February 5th 2016, 8:56 pm

    The login widget should do that. I'm pretty sure if they login through that widget, they will be directed to the same page.
    OMMA
    OMMA
    Forumember


    Male Posts : 59
    Reputation : 1
    Language : English
    Location : USA

    Solved Re: I need a "redirect after log in" code

    Post by OMMA February 5th 2016, 9:33 pm

    Thanks for your reply. I tried it and no it still redirects to the index. I do not want to add a widget to the forums though. I want this to be done with the normal log in from the navigation bar.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: I need a "redirect after log in" code

    Post by Ange Tuteur February 5th 2016, 9:55 pm

    Hi @OMMA,

    Try the following.

    Go to Modules > JavaScript codes management and create a new script with these settings :

    Placement : In all the pages
    Code:
    /\/login/.test(window.location.href) && $(function() {
      var redirect = '/forum';
      if (!_userdata.session_logged_in) {
        $('form[name="form_login"]')[0].redirect = redirect;
      }
    });

    To change the redirect URL simply modify the redirect variable.
    OMMA
    OMMA
    Forumember


    Male Posts : 59
    Reputation : 1
    Language : English
    Location : USA

    Solved Re: I need a "redirect after log in" code

    Post by OMMA February 5th 2016, 10:39 pm

    Thanks Ange but it didn't work. Still redirects to the index. Basically what I'm trying to do is lessen the amount of clicks to get to specific pages. Right now if someone is viewing a certain page and log in they are redirected to the index and have to click their way back to the page they were on to post. I guess the portal or an HTML page could be a HUB that is used for shortcuts but I cant get either to work. I've made them both the homepage and also activated them but when I log in it still always redirects to the index so I'm basically trying to find a workaround. If you can help me get the portal or homepage to always show up when a person registers or logs in that would be great though.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: I need a "redirect after log in" code

    Post by Ange Tuteur February 5th 2016, 10:48 pm

    Is the script still installed ? I checked your forum, but I didn't see any installed scripts. Just to be sure, make certain that JS codes management is enabled.

    The option will be above the installed script list.
    I need a "redirect after log in" code Captur20
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51499
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: I need a "redirect after log in" code

    Post by SLGray February 5th 2016, 11:09 pm

    Are you wanting where everyone is redirected to what they are reading as a guest?



    I need a "redirect after log in" code Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19325
    Reputation : 2005
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: I need a "redirect after log in" code

    Post by Ape February 6th 2016, 2:01 am

    What the member is asking for if i have this right is.

    Say im looking at this post as a guest and i think Wow i want to post in this thread and i lick login now it will log me in but take me to the home page.

    what the member want is to stay right here and get to type in this thread without going back to the home / forum page.

    come to think of it i want the same thing for my sites LOL Razz



    I need a "redirect after log in" code Left1212I need a "redirect after log in" code Center11I need a "redirect after log in" code Right112
    I need a "redirect after log in" code Ape_b110
    I need a "redirect after log in" code Ape1010
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1442
    Reputation : 220
    Language : English

    Solved Re: I need a "redirect after log in" code

    Post by SarkZKalie February 6th 2016, 4:29 am

    Find this line in your overal_header template
    Code:
    <script src="{JS_DIR}{L_LANG}.js" type="text/javascript"></script>
    Then, add this code after it
    Code:
    <script type="text/javascript">document.write('<input type="hidden" name="redirect" value="' + location.href + '" />')</script>
    Save and publish it! Twisted Evil



    I need a "redirect after log in" code Sarkzk10
    Pamoon
    Pamoon
    Forumember


    Posts : 28
    Reputation : 10
    Language : en.js

    Solved Re: I need a "redirect after log in" code

    Post by Pamoon February 6th 2016, 2:01 pm

    Just paste this
    Code:
    <script type="text/javascript">document.write('<input type="hidden" name="redirect" value="' + location.href + '" />')</script>
    before </form> in your login form if youre using a custom login.
    OMMA
    OMMA
    Forumember


    Male Posts : 59
    Reputation : 1
    Language : English
    Location : USA

    Solved Re: I need a "redirect after log in" code

    Post by OMMA February 6th 2016, 9:15 pm

    APE wrote:What the member is asking for if i have this right is.

    Say im looking at this post as a guest and i think Wow i want to post in this thread and i lick login now it will log me in but take me to the home page.

    what the member want is to stay right here and get to type in this thread without going back to the home / forum page.

    come to think of it i want the same thing for my sites LOL Razz
    Yes this exactly.

    @SarkZKalie it didn't work. I'm still taken to the index when I log in.
    SarkZKalie
    SarkZKalie
    Support Moderator
    Support Moderator


    Male Posts : 1442
    Reputation : 220
    Language : English

    Solved Re: I need a "redirect after log in" code

    Post by SarkZKalie February 7th 2016, 1:50 am

    Try this tutorial or you can do as Forumedic says
    OMMA
    OMMA
    Forumember


    Male Posts : 59
    Reputation : 1
    Language : English
    Location : USA

    Solved Re: I need a "redirect after log in" code

    Post by OMMA February 10th 2016, 5:54 am

    SLGray wrote:Are you wanting where everyone is redirected to what they are reading as a guest?
    Yes. If a person is reading a thread as a guest and decides he wants to joi the discussion he logs in and is redirected to that thread instead of to the index.

    @SarkZKalie that didn't work either. I'm still sent to the index when I log in.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: I need a "redirect after log in" code

    Post by Ange Tuteur February 10th 2016, 3:31 pm

    Hmm.. I think I understand what you mean now. Try giving the following script a try :

    Placement : In all the pages
    Code:
    $(function() {
      if (!_userdata.session_logged_in) {

        if (/\/login/.test(window.location.href)) {
          var form = document.form_login, cookie = my_getcookie('fa_last_page');
          if (form) form.redirect.value = cookie ? cookie : '';
        } else {
          my_setcookie('fa_last_page', window.location.pathname);
        }

      }
    });

    The last page visited is stored to a cookie, except while viewing the login page. So, once you click onto the login page it should set the redirect value to the previously viewed page. Let me know if that's what you want.
    OMMA
    OMMA
    Forumember


    Male Posts : 59
    Reputation : 1
    Language : English
    Location : USA

    Solved Re: I need a "redirect after log in" code

    Post by OMMA February 19th 2016, 11:14 pm

    Yes that's it! cheers Thank you very much Ange. You are an awesome guy on these forums. You seem to have all the answers. Thanks again. This can be marked as solved now.
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51499
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: I need a "redirect after log in" code

    Post by SLGray February 19th 2016, 11:15 pm

    Topic solved and archived



    I need a "redirect after log in" code Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.