Using API Lite, want to redirect to previous URL after logging in

Discussion in 'Setting-up protection' started by chai714, Nov 28, 2016.

Thread Status:
Not open for further replies.
  1. chai714

    chai714 New Member

    Joined:
    Apr 28, 2014
    Messages:
    18
    I would like to redirect users back to the page on which they first clicked the login link. I'm using the API lite on a PHP page. Is this possible?

    Thank you.

    If this helps, here's the code I'm using to render the login form:

    Code:
    <?php
    include 'path/to/amember/library/Am/Lite.php';
    echo Am_Lite::getInstance()->renderLoginForm();?>
    
  2. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    Put the URL into the call eg
    PHP:
    renderLoginForm("https://example.com/myLink");
  3. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can get current URL from environment ie. $_SERVER['REQUEST_URI']
    So complete code is:
    PHP:
    <?php
    include_once 'path/to/amember/library/Am/Lite.php';
    echo 
    Am_Lite::getInstance()->renderLoginForm($_SERVER['REQUEST_URI']);
    ?> 
  4. chai714

    chai714 New Member

    Joined:
    Apr 28, 2014
    Messages:
    18
    My apologies. I probably did not explain it correctly the first time.

    My login page is a standalone page. Let's call that, Page 1.

    Guests will click the "login" link on "Page 2" which will take them to Page 1 to login. Upon logging in, they should be redirected back to Page 2, where they will be able to view members content.

    Page 1 Link: https://goo.gl/SpNCyO
    Page 2 (login) Link: https://goo.gl/A90ZYq
  5. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can use this code in such case:
    PHP:
    <?php
    include_once 'path/to/amember/library/Am/Lite.php';
    echo 
    Am_Lite::getInstance()->renderLoginForm($_SERVER['HTTP_REFERER']);
    ?> 
  6. chai714

    chai714 New Member

    Joined:
    Apr 28, 2014
    Messages:
    18
    Hi Caesar,

    I've implemented the suggestion however I think the options in the control panel are overriding the php code? I'm not sure. I've tried all options in the dropdown box (image below) and added in your suggested code. I can provide full access to my template and control panel if necessary.

    [​IMG]
    [​IMG]
  7. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    chai714 likes this.
  8. chai714

    chai714 New Member

    Joined:
    Apr 28, 2014
    Messages:
    18
    This issue has been resolved thanks to the Amember team. Thank you guys so much for your generosity and expertise!
  9. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page