No return from Am_Lite::getInstance()->getUsername()

Discussion in 'aMember Pro v.4' started by stratkm, Jan 20, 2012.

  1. stratkm

    stratkm New Member

    Joined:
    Jan 10, 2012
    Messages:
    7
    Hello,
    I need to access the username for the logged in user and have tried using the API/Lite functions.
    If I try this:

    echo Am_Lite::getInstance()->getUsername();
    echo Am_Lite::getInstance()->getEmail();
    echo Am_Lite::getInstance()->getLogoutURL();

    Then I get the URL back, but the username and email are both blank. I'm definitely logged in, as I can access restricted content and see my user details in the membership area.

    Is there anything I can do?
    Thanks
  2. glacius

    glacius New Member

    Joined:
    Jan 11, 2012
    Messages:
    24
    Did you put
    at the top of the pages where you are doing this?
  3. stratkm

    stratkm New Member

    Joined:
    Jan 10, 2012
    Messages:
    7
    Yes - I've got that at the top of the page:

    <?php

    include_once('/home/username/public_html/amember/library/Am/Lite.php');

    echo Am_Lite::getInstance()->getName();
    echo Am_Lite::getInstance()->getLogoutURL();​

    ?>
    Calling this page brings back the URL so I know the path is correct
    Thanks
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Can you contact us in helpdesk and attach phpinfo(); output and also, provide url to the page that contain above code and any login/password to test it.
  5. stratkm

    stratkm New Member

    Joined:
    Jan 10, 2012
    Messages:
    7
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Btw, this will be fixed in next verson. It will not require that option to be disabled.
  7. stratkm

    stratkm New Member

    Joined:
    Jan 10, 2012
    Messages:
    7
    Now this is working I've noticed that I can still see the protected content after amember has timed out - as this is returning
    blank​
    :
    echo Am_Lite::getInstance()->getName();​

    and if I go to the members page it asks me to log in again. At which point I get the username back from the getName function properly.​

    How does amember handle timeouts? as I need it to redirect users back to the login page if there aren't logged in - something which I assume it would do automatically!​
  8. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    It could be done automatically, but we decided to give more control to developer.

    PHP:
    $lite Am_Lite::getInstance();
    if (!
    $lite->isLoggedIn())
    {
          
    header("Location: " $lite->getLoginUrl($_SERVER['REQUEST_URI']));
          exit();
    }
  9. stratkm

    stratkm New Member

    Joined:
    Jan 10, 2012
    Messages:
    7
    Many thanks again - this solves the problem!

Share This Page