Insert Login/Logout to any page

Discussion in 'Customization & add-ons' started by dudaah, Jun 9, 2004.

  1. dudaah

    dudaah Guest

    No problem with the actual logout link from the documentation but I have a question though. There's no need for that link to show up when a visitor is not logged in. How can I

    1. Hide the logout link when the visitor IS NOT logged in?

    2. Hide the login fields when the user IS logged in?

    Any smart coders in here that could help me out with this one because I'm stuck right now.

    Thanks!
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Use this PHP code:

    PHP:
    <?php
    session_start
    ();
    if (
    $au=$_SESSION['_amember_user']){ // user is logged-in
      
    print "Hello $au[name_f] $au[name_l]!<br>";
      print 
    "<a href='/amember/logout.php'>Logout</a>";
    } else { 
    // user is not logged-in
      
    print "<form method=post action='/amember/login.php'>
      Username: <input type=text name=amember_login size=10><br>
      Password: <input type=password name=amember_pass size=10><br>
      <input type=submit value='Login'>
      </form>"
    ;
    }
    ?>
  3. dudaah

    dudaah Guest

    thanks!!!

    Great one - much appreciated!
  4. dudaah

    dudaah Guest

  5. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Sorry, forgot to mention.
    If you get error messages like this:

    Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/pitch/pidfgdfg/html/site/front.php:194) in /home/pitch/pitdfgdsf/html/site/front.php on line 403

    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/pitch/pidfgdfg/html/site/front.php:194) in /home/pitch/pdfgdfg/html/site/front.php on line 403


    then you have to put line
    <?php session_start(); ?>
    to VERY top of your PHP file. No output, no spaces must be before this line.
  6. dudaah

    dudaah Guest

    hmmm

    well that took care of the error messages but nothing happens with the if and else thing. I still see the login form and no logout link.
  7. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    please replace line
    if ($au=$_SESSION['amember_user']){
    to
    if ($au=$_SESSION['_amember_user']){

    I also fixed code above.
  8. dudaah

    dudaah Guest

  9. sdk089

    sdk089 Guest

  10. dudaah

    dudaah Guest

    hehe

    Sorry but muchos gracias was pretty much all the Spanish I know so I have absolutely no clue what you are writing mate? :)
  11. ujohnc00

    ujohnc00 Guest

    Hi.

    I tried adapting the code to some like this (in config.inc.php):

    session_start();
    $logged_in = false;
    if ($au=$_SESSION['_amember_user']){
    $logged_in = true;
    }

    This way, I have a more useful boolean variable on which I can conditionally display content etc.
    Would this work? If so, how can I access this from smarty, because {if $logged_in} is not working for me?

    Thanks!
  12. ujohnc00

    ujohnc00 Guest

    Does anyone have any ideas about why the code in the previous post doesn't work?

    Thanks
  13. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    If you really need answer, please contact support with exact information.
  14. phoenix

    phoenix New Member

    Joined:
    Aug 22, 2006
    Messages:
    2
    EDIT: Fixed my problem :eek:

    Yes, I'm a PHP n00b.
  15. kilerb

    kilerb New Member

    Joined:
    Apr 16, 2007
    Messages:
    20
    Hi just purchased Amember and got it working nicely. I've been reading all the forum messages, and this posting seemed like the closest thing I'm trying to accomplish. When I enter this coding here...
    <form action="/amember/login.php" method=post>
    Username: <input type=text name=amember_login size=10><br>
    Password: <input type=password name=amember_pass size=10><br>
    <input type=checkbox name=remember_login value=1>Remember me
    <input type=submit value=Login>
    </form>

    I do get a login section on my main page with a remember me check box. I've tried using the codes mentioned above in this thread so after someone logs in, the login box disappears and it just says they are logged in, which is what I'd really like to have on my site, however, when I put any of these codes on my page, I get nothing there at all. No login box or anything. Why would this be the case? I read on another thread that .htm pages can't do certain things that php pages can? Is this the problem? Because my main page is called index.htm. If this is the problem, can I change the extention to .php or do something else so I can do this? I want the user to know they are logged in. Thanks a lot!!!
  16. draj

    draj New Member

    Joined:
    Dec 29, 2006
    Messages:
    252
    Hi!
    Use the following in your htm (changing to php is not necessary!):

    {if $smarty.session._amember_products}
    Hi just purchased Amember and got it working nicely.
    {else}
    <form action="/amember/login.php" method=post>
    Username: <input type=text name=amember_login size=10><br>
    Password: <input type=password name=amember_pass size=10><br>
    <input type=checkbox name=remember_login value=1>Remember me
    <input type=submit value=Login>
    </form>

    {/if}
  17. kilerb

    kilerb New Member

    Joined:
    Apr 16, 2007
    Messages:
    20

    I know I'm new, but is the "Hi just purchased Amember and got it working nicely supposed to be in the middle of the code like that? Sorry, i'm sure it's a dumb question, I just can't tell where the code begins I guess. Thanks...
  18. kilerb

    kilerb New Member

    Joined:
    Apr 16, 2007
    Messages:
    20
    Okay, I just did the code from <form to </form> and when i log in, it still has the login and password option there... How do I make it turn into a logout option instead?
  19. draj

    draj New Member

    Joined:
    Dec 29, 2006
    Messages:
    252
    Hello!

    Oh man, I though you would understand my sense of humour. I would normally not make such jokes with people who do not have any or much of programming knowledge. I thought that you would understand.

    Now that you have clearly reflected in this regards, I offer once again the correct codes. Please insert exactly what is below:

    Method Login table:

    {if $smarty.session._amember_products}
    <a href="logout.php">Logout</a>
    {else}
    <form action="login.php" method=post>
    Username: <input type=text name=amember_login size=25><br>
    Password: <input type=password name=amember_pass size=25><br>
    <input type=checkbox name=remember_login value=1>Remember me
    <input type=submit value=Login>
    </form>
    {/if}

    The above codes will generate a login box (without html design!). You could design html and insert the login codes that starts from {else} ... {/if} into it. After a person is logged in successfully, that login box will disappear and in that place a logout link will appear automatically.

    Also you can change the size=25 to any value you want, like size=30, size=50,...

    Method Login links:

    {if $smarty.session._amember_products}
    <a href="logout.php">Logout</a>
    {else}
    <a href="login.php">Login</a>
    {/if}

    If you do not want to see a login box i.e. Username and passwords fields, then you could simply place the above codes to generate html links. By clicking on those links, it will redirect to the respective login and logout pages of aMember.

    The link references link <a href="log...... could be replaced by your website URL. After replacing it will look like following:

    <a href="http://www.website.com/logout...

    action="login.php", href="logout.php", action="login.php" must also have correct references to their respective directories, however it could be relative (i.e. without website URL) or absolute (with URL like http://www.website.com).

    Please feel free to ask if you have problems. May be you need help for all the designs...
  20. kilerb

    kilerb New Member

    Joined:
    Apr 16, 2007
    Messages:
    20
    I copied your code right where my basic login box was before, and this is what I get... Here's a screen capture of that login area... http://www.deepspacemine.com/login.jpg

    For some reason it seems the parts of the code in the brackets {} keep just coming up as text for some reason. I'm using frontpage 2003 in case that matters. It seemed to work fine for the regular code box though. Just not this fancier one that changes to logout after you login.

    Thanks again...

Share This Page