how to tell when logged in

Discussion in 'Integration' started by FirestormX, Apr 3, 2004.

  1. FirestormX

    FirestormX Guest

    hi,
    I want to try and make it so that when someone is not logged in, it shows a "login" button on my main page, but if they are logged in, if doesn't show the login button.
    so I was just wondering how amember knows when you are logged in, so that I can make my page know when you are logged in, to display the login button or not. (I know enough php to make it display the button, but anything harder than that, and you may need to explain ;))
    Thanks
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    It's easy:

    PHP:
    <?php
    session_start
    ()
    if (
    $l=$_SESSION['_amember_login']){
      
    $u $_SESSION['_amember_user'];
      print 
    "Hello $u[name_f] $u[name_l]!<br>";
    } else {
      print 
    "<form method=post action='/amember/login.php'>
     Login: <input type=text name=amember_login><br>
     Password: <input type=password name=amember_pass><br>
      <input type=submit value=Login>
    </form>"
    ;
    }

    ?>
  3. iantresman

    iantresman Guest

    When I first tried this code snippet, I received the following error message:

    Code:
    Warning: Cannot send session cache limiter - headers already sent
    I solved the problem by moving the following line to the very start of my PHP file, before the <html> tag:

    Code:
    <?php session_start() ?>
    And then the remaining code, which now works fine, becomes:

    Code:
    <?php
    if ($l=$_SESSION['_amember_login']){
      $u = $_SESSION['_amember_user'];
      print "Hello $u[name_f] $u[name_l]!<br>";
    } else {
      print "<form method=post action='/amember/login.php'>
    Login: <input type=text name=amember_login><br>
    Password: <input type=password name=amember_pass><br>
      <input type=submit value=Login>
    </form>";
    } 
    
    Regards,
    Ian Tresman

Share This Page