Header / logged in, username

Discussion in 'Integration' started by slinky, Nov 15, 2010.

  1. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Now that I've got a very impressive 4 signup login, I need a way to have the header change to show that a user is logged in. My header consists of a standard PHP template and it has the login links to login to amember. I'd like it to be gone when logged in and replaced by "Welcome, username!" or something like that. As this is external to amember itself and I am not using smarty, what have you guys done to deal with this common issue? Hope it's easily solved....
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
  3. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Awesome... I can't wait. I have really customized the amember login so that it's an extremely impressive front end that integrates the various parts of my site. This part will completely it - thanks for pointing me to the missing final link. :)

    The last part will be the question of whether I want to include the Facebook integration I bought and whether it is more pain than pleasure.
  4. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Not sure why -

    I'm getting these errors. I've stuck the sessionstart in the header.php which is what is on line 8. The index.php file includes the header.php and I'm getting this error. Not quite sure why. Not sure - do I need to see whether it has been called by another class already and use an "if not called then include this file" directive in my header.php? Would much appreciate the assistance... almost there!

    Code:
    [Tue Nov 16 00:38:14 2010] [error] [client 333.333.333.333] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/myaccount/public_html/directory/index.php:297) in /home/myaccount/public_html/nav/header.php on line 8
    
    [Tue Nov 16 00:38:14 2010] [error] [client 333.333.333.333] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/myaccount/public_html/directory/index.php:297) in /home/myaccount/public_html/nav/header.php on line 8
  5. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Couple of things to check:

    1) open the following files and ensure there are no empty spaces / extra carriage returns at the bottom of them. If there are delete them and save the file:

    /home/myaccount/public_html/directory/index.php
    /home/myaccount/public_html/nav/header.php

    2) Any chance that session is being started through some other part of your website? What are you using for your CMS?
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    session_start() function call should be before any other html code or php output.
    Move it to the top of the file.
  7. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Thanks - this did it.
  8. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Unfortunately the error is gone but now I'm finding that the top area does not change if you are logged into certain scripts. It still says the standard login. When I view wordpress, it does show that the user is logged in and shows a logout instead. Doesn't happen in vBulletin. Anyone else have this issue or perhaps can explain what is going on? I am using a common php file so it's not a typo and the code works, just only for WP but not VB.
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    What code you use in order to check is user logged in or not?
  10. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    PHP:
    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print "Hello $au[name_f] $au[name_l]! &nbsp;|&nbsp; ";
    print 
    "<a href='/amember/logout.php'>Logout</a>";
    } else { 
    // user is not logged-in
    print "<span class='linkstop' style='font-weight:bold;'><a class='t' href='http://www.mysite.com/amember/member.php'>Login</a> <span style='color:#43525B;'>or</span> 
    <a class='t' href='http://www.mysite.com/amember/'>Join</a>"
    ;
    }
    ?> 
    This isn't working on general PHP pages (session start is right at the top, first thing) and also not in vbulletin. I'm not sure if session start is there too but I'd certainly need a little help in how to set that part up to make sure it's correct.

    Additionally, it's difficult to put an amember username/password fields into vbulletin and have it login correctly. It's just not working despite looking at the instructions carefully.
  11. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    @slinky: for testing, have you tried printing out your $_SESSION values to see if the session is actually being started correctly?
  12. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Checking that right now and will report back. MUCH appreciate your helping me get all this off the ground... and then later maybe do funky things. :)
  13. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Apparently it is not working. I get parse errors.

    This works:

    print "Hello $au[name_f] $au[name_l]! &nbsp;|&nbsp; ";

    But it only provides first name and last name - not what I want. I want user name!

    This gives me a parse error:

    print "Hello $_SESSION['_amember_user']! &nbsp;|&nbsp; ";

    and none of the user ones print properly either:

    $user

    That is completely blank...
  14. slinky

    slinky Member

    Joined:
    Jul 15, 2010
    Messages:
    200
    Got it. I don't know if it is old code, this is not in the manual but this is how I got what I wanted -- login is the variable. OK, solved that part

    PHP:
    <?php
    session_start
    ();
    $user $_SESSION['_amember_user'];
    if (
    $user['member_id'] > 0){
        print 
    "Your name is $user[login] <br>\n";
    } else {
        print 
    "You are not logged-in";
    }
    ?>

Share This Page