Amember Cookies & Remember Password

Discussion in 'Integration' started by schmitt, Jan 29, 2008.

  1. schmitt

    schmitt New Member

    Joined:
    Oct 26, 2007
    Messages:
    28
    I display conditional login links and text on every page depending on whether a user is logged in. The relevant code is straight out of the FAQ.

    Code:
                  
    <?php session_start(); // Very first line of code ?>
    
    ~~~~~~~~~~~~~~~~~~
    
    
            <?php // Populate amemuser, run code to display welcome link
                  if ($amemuser=$_SESSION['_amember_user']){ // logged-in
                  print "Welcome, $amemuser[login]  |  ";
                  print "<a href='/amember/logout.php'>Logout</a>";
                  } else { // user is not logged-in
                  print "<a href='/amember/login.php'>Login</a>";
                  } ?>
    
    This works fine. However, if a user who has checked "Remember my password" closes the browser and returns, the code does not detect the returning user. If the user clicks on the 'login' link they are automatically logged in using the account stored in the cookie.

    It appears to me that session_start is not sufficient to populate $_SESSION['_amember_user'] with the returning users data. Once amember is invoked by going to a login screen the cookies are read and the user is authenticated. Is there an amember script I can 'hit' to refresh cookies if I detect these variables are not set? Why is this not working?

    I should add I am using the wordpress plugin and am running a wordpress site but I don't think that makes a difference here. All other wordpress integration is working fine.

    I searched the forums extensively - I am surprised I am the only one with this issue.

    Thanks in advance.
  2. schmitt

    schmitt New Member

    Joined:
    Oct 26, 2007
    Messages:
    28
    From Amember support:

    You need to include this code at the top of your pages where you have your code:
    include "/full/path/to/amember/plugins/protect/php_include/reload_if_cookie.inc.php";
    This will restore session variables from cookies.

    ... and it works like a charm.
  3. deafdavid

    deafdavid Member

    Joined:
    Aug 28, 2006
    Messages:
    153
    schmitt, which file am I suppose to include the code? login.php?
  4. schmitt

    schmitt New Member

    Joined:
    Oct 26, 2007
    Messages:
    28
    reload_if_cookie.php

Share This Page