redirect after login

Discussion in 'Customization & add-ons' started by Stim_Pey69, Mar 25, 2009.

  1. Stim_Pey69

    Stim_Pey69 New Member

    Joined:
    Mar 24, 2009
    Messages:
    2
    I noticed after testing my log in button on my website that it redirects to the amember/member.php page. Is there a way to have it simply redirect back to the page I was currently on?
  2. codeispoetry

    codeispoetry aMember Pro Customer

    Joined:
    Jan 12, 2009
    Messages:
    336
    Hi ckearns,

    Use hidden amember_redirect_url="some value" in your login form.

    If you need help with that, email me codeispoetry [at] amemberincremental.com

    Lee
  3. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Add this to your login forms:

    <input type="hidden" name="amember_redirect_url" value="/redirect_url/>"/>

    David
  4. signal

    signal aMember Pro Customer

    Joined:
    Feb 12, 2009
    Messages:
    5
    Is it possible to redirect product homepage after login? If so which code I must use?
  5. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Can you explain what you mean?

    David
  6. femur

    femur aMember Pro Customer

    Joined:
    Mar 9, 2009
    Messages:
    25
    Interested in this solution

    I'm very interested in this as well. I'm setting up the form so users can log in from any page on the site. Once they're logged in, i'd like them to return to the page they were on.

    I tried adding Davidm1's code to the form, and it doesn't quite work for me. After logging in, it attempts to redirect as follows:

    http://mysite.com/redirect_url/>

    I'm sure I've done something wrong. If anyone can offer some advice, I'd greatly appreciate it!

    I should add that what I'm looking for is a solution that can be dropped into all pages on the site as a php include, so the login form will redirect back to the page it's on (without having to enter a specific URL for every page).
  7. femur

    femur aMember Pro Customer

    Joined:
    Mar 9, 2009
    Messages:
    25
    Ahhhh... got it.

    <input type=\"hidden\" name=\"amember_redirect_url\" value=\"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\">
  8. signal

    signal aMember Pro Customer

    Joined:
    Feb 12, 2009
    Messages:
    5
    In "Manage Product" section there is a parameter " Product URL (Please enter URL of protected area...)" Is it possible to redirect this URL after login?
  9. codeispoetry

    codeispoetry aMember Pro Customer

    Joined:
    Jan 12, 2009
    Messages:
    336
    Hey signal,

    If your member has only 1 product purchased, and he logged in via yoursite.com/amember/login.php, he will be redirected to the Product URL.

    Cheers,
    Lee
  10. signal

    signal aMember Pro Customer

    Joined:
    Feb 12, 2009
    Messages:
    5
    this is great info and solves my problem

    Thank you very much
  11. codeispoetry

    codeispoetry aMember Pro Customer

    Joined:
    Jan 12, 2009
    Messages:
    336
    Hey signal,

    My pleasure ;) Glad to help out.

    Cheers,
    Lee
  12. sdstren

    sdstren New Member

    Joined:
    Nov 30, 2007
    Messages:
    14
    I found this thread trying to solve the same problem. I am so close I can taste it, but I just can't quite figure out where/how to make the recommended changes. I have the standard files, login.html, and login.php that comes with amember.

    I too, want the user to return to the page they were on when they invoked login.php.

    This thread recommended a line of code:

    <input type=\"hidden\" name=\"amember_redirect_url\" value=\"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\">

    I just can't figure out specifically which file it goes in and where, and if any of this code is symbolic or if I should take it all as literal.

    Can someone help un muddy the water for me? I feel like this will fix what I need to do if I can just figure it out.
  13. akanowicz

    akanowicz New Member

    Joined:
    Feb 19, 2007
    Messages:
    31
    I too would like to do this (redirect back to where the user logged in from).

    Where in the login form does it go?
    Are those \ escape characters necessary?

    thank you,
    Ron
  14. powerkeys

    powerkeys Member

    Joined:
    Aug 29, 2006
    Messages:
    192
    The line used above as an example, which for reference is:
    Code:
    <input type=\"hidden\" name=\"amember_redirect_url\" value=\"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\">
    is meant to go into a PHP file (or perhaps a template file), inside the login form.

    This will direct the server to replace the $_SERVER[] variables with the actual URL the member is at when they log in, which in turn will tell aMember where to send the member to after logging them into the system.

    On my site, I found a bit of javascript to do the same thing. Here's my login form code:

    Code:
    <form method="post" action="/amember/login.php">
        <script type="text/javascript" language="JavaScript"><!--
    document.write('<input ');
    document.write('   type="hidden" ');
    document.write('   name="amember_redirect_url" ');
    document.write('   value="' + document.URL + '">');
    //--></script>
    
        <p>Username:<br />
        <input type="text" size="15" name="amember_login" /></p>
        <p>Password:<br />
        <input type="password" size="15" name="amember_pass" /></p>
        <p><input type="submit" value="Login" /></p>
    </form>
    
    With this, I can send my members links to new pages, and all they have to do is click the link and login to see the intended page.
  15. akanowicz

    akanowicz New Member

    Joined:
    Feb 19, 2007
    Messages:
    31
    and does that replace code within the login.html page or get added in addition to what's there (and if so, where?)
  16. powerkeys

    powerkeys Member

    Joined:
    Aug 29, 2006
    Messages:
    192
    My login form is on a separate page not created by aMember.

    If you don't understand the PHP code equivalent, it's best not to try to use it.
  17. apetersen

    apetersen New Member

    Joined:
    Sep 10, 2008
    Messages:
    13
    That doesn't seem to work for me. The form is calling the login.php and the script redirects to whatever product is first (if user has multiple products). Adding the amember_redirect_url value and setting it to member.php makes all login go through member.php. What am I missing?
  18. robertbruce

    robertbruce New Member

    Joined:
    Apr 4, 2008
    Messages:
    15
    David, is this to be added to the login.php or login.html file?
  19. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    login.html

    David
  20. robertbruce

    robertbruce New Member

    Joined:
    Apr 4, 2008
    Messages:
    15
    Thank you for clearing up my confusion:D

Share This Page