I just migrated from v3 to v4 and in v3 I used a session variable to allow users to login. The below code is an example of what is at the top of the template for all of my pages. Code: <?php if ($au=$_SESSION['_amember_user']){ // user is logged-in print "Welcome $au[name_f] $au[name_l]! "; print "<a href='/amember/logout.php'>Logout</a>"; print "<a href='/amember/profile.php'> | Manage Account</a>"; } else { // user is not logged-in print "<form method=post action='/amember/login.php'> Username: <input type=text name=amember_login size=10> Password: <input type=password name=amember_pass size=10> <input type=submit value='Login'> </form>"; } ?> This doesn't work since I migrated to v4. Can I do something similar to this in v4? What would be my easiest path to changing this? Would love some ideas as currently, no one can log in to the site.
You can achieve a similar result in V4 but rather than session variables you will probably need to use Am_Lite::getInstance()->isLoggedIn() for instance. Full details, including other routines to recover username etc. at http://www.amember.com/docs/API/Lite
Thank you. How do I install the API module? I upgraded to the latest version 4.2.9 but the API module is not there. I have it downloaded but don't know how I should go about installing it.
In v4 the session variables changed significantly. You can examine these by running either of these commands. PHP: require_once '/member/bootstrap.php';print_r($_SESSION);var_dump($_SESSION); echo $_SESSION["amember_auth"]["user"]["name_f"]); //first nameecho $_SESSION["amember_auth"]["user"]["name_l"]); //last name Note: You may need to change the path to your bootstrap.php file Alternatively, and probably the better solution, you can use thehpmc's suggestion. You don't need to install/enable anything to use the code below. PHP: require_once '/member/bootstrap.php'; if(Am_Lite::getInstance()->isLoggedIn()){ echo 'is logged in';}