Displaying Username

Discussion in 'Templates customization' started by gungeuk, May 6, 2011.

  1. gungeuk

    gungeuk New Member

    Joined:
    Aug 13, 2010
    Messages:
    9
    Hiya,
    I have read the guide and can't figure out how to display the username when someone is logged in.
    I am doing it via header.php to make it global across the site, here is my code:

    PHP:

      <div id="nav-links"> 
                <ul> 
                    <li><a href="/index2.php" onfocus="this.blur();" >Home</a></li> 
                    <li>
    <?php
    print "Welcome, " $_SESSION['_amember_user']['name_f'] . " " $_SESSION['_amember_user']['name_l'];
    ?>
                    </li>
                    <li></li>
                    
                    <!--<li><a href="#"></a></li>--> 
                              <!--<li><a href="" title="" ></a></li>--> 
                          </ul> 
            </div> 
    On the first line of header.php, I have:

    PHP:
    <?php session_start(); ?>
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    This code should work.
    Try to output session array just after session_start() do you see aMember session variables?
    PHP:
    <?php 
    session_start
    (); 
    var_dump($_SESSION);
  3. gungeuk

    gungeuk New Member

    Joined:
    Aug 13, 2010
    Messages:
    9
    All I see when using that code is a white page, with:
    array(0) { }
    At the top left corner.

    I've read both guides in the manual and can't seem to sort anything out with it, It will either say "you are not logged in" or give a syntax error :(

    I have 2 headers, the one it is calling is /includes/members/header.php, with that containing:

    PHP:

    <?php
    session_start
    ();
    var_dump($_SESSION);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb"> 
    <head> 
    <title>Sianyde</title> 
     
    <link rel="shortcut icon" href="/styles/loora/images/favicon.ico" type="image/vnd.microsoft.icon" /> 
     
    <!-- Sianyde.meta.start --> 
    <meta name="google-site-verification" content="YYeSht6_ej0gsTRICmr-cHs6syZ96jMq1HR0TZ7_FkY" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="Content-Style-Type" content="text/css" /> 
    <meta http-equiv="Content-Language" content="en-gb" /> 
    <meta name="description" content="Sianyde" /> 
    <meta name="keywords" content="sianyde, website, content, internet, software, hardware, computers" /> 
    <meta name="language" content="en-gb" /> 
     
    <!--[if IE 8]>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <![endif]--> 
    <!-- Sianyde.meta.end --> 
     
    <!-- Sianyde.stylesheets.start --> 
    <link href="/css/stylesheet.css" rel="stylesheet" type="text/css" media="screen" /> 
    <link href="/css/index.css" rel="stylesheet" type="text/css" media="screen" /> 
    <link href="/css/shadowbox.css" rel="stylesheet" type="text/css" media="screen" /> 
     
    <!--[if IE]>
    <link href="/styles/loora/ie.css" rel="stylesheet" type="text/css" />
    <![endif]--> 
     
    <!--[if lt IE 7]>
    <link href="/styles/loora/ie6.css" rel="stylesheet" type="text/css" />
    <![endif]--> 
     
    <!--[if IE 7]>
    <link href="/styles/loora/ie7.css" rel="stylesheet" type="text/css" />
    <![endif]--> 
    <!-- Sianyde.stylesheets.end --> 
     
    <!-- Sianyde.javascript.start --> 
    <script src="/js/core.utils.js" type="text/javascript" charset="utf-8"></script> 
    <script src="/js/core.forms.js" type="text/javascript" charset="utf-8"></script> 
    <script src="/js/jquery.js" type="text/javascript" charset="utf-8"></script> 
    <script src="/js/jquery.cycle.lite.min.js" type="text/javascript" charset="utf-8"></script> 
    <script src="/js/core.sessions.js" type="text/javascript" charset="utf-8"></script> 
    <script src="/js/shadowbox.js" type="text/javascript" charset="utf-8"></script> 
     
     
    <script type="text/javascript"> 
    // <![CDATA[
    jQuery.noConflict();
     
    jQuery(document).ready(function() {
        jQuery("#page-content").addClass("hidden");
     
        jQuery("#page-content").animate({
            width: "100%"
        }, 500);
     
        jQuery("#header-image").cycle({
            fx: "fade",
            timeout: 10000,
            speed: 3000
        });
     
        jQuery("a").focus(function() {
            jQuery(this).blur();
        });
    });
    // ]]>
    </script> 
    <!-- Sianyde.javascript.end --> 
    </head> 
     
    <body> 
     
    <!-- Sianyde.cp.start --> 
        
    <div id="cp-wrapper"> 
        <div id="control-panel"> 
            <div id="nav-links"> 
                <ul> 
                    <li><a href="/index2.php" onfocus="this.blur();" >Home</a></li> 
                    <li>

                     <?php
                      $user 
    $_SESSION['_amember_user'];
    if (
    $user['member_id'] > 2){
        print 
    "Hello $user[name_f] $user[name_l] <br>\n";
        print 
    "Your E-Mail address is $user[email] <br>\n";
        print 
    "Your subscription status is $user[status] <br>\n";
    } else {
        print 
    "You are not logged-in";

                      
    ?>
                    </li>
                    <li></li>
                    
                    <!--<li><a href="#"></a></li>--> 
                              <!--<li><a href="" title="" ></a></li>--> 
                          </ul> 
            </div> 
            <div id="date"> 
               <script>

    /*Current date script credit: 
    JavaScript Kit (www.javascriptkit.com)
    Over 200+ free scripts here!
    */

    var mydate=new Date()
    var year=mydate.getYear()
    if (year < 1000)
    year+=1900
    var day=mydate.getDay()
    var month=mydate.getMonth()
    var daym=mydate.getDate()
    if (daym<10)
    daym="0"+daym
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    document.write(""+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"")

    </script></div> 
        </div> 
    </div> 
    <!-- Sianyde.cp.end --> 
     
    <div id="wrapper"> 
        <a id="top">&nbsp;</a> 
     
        <!-- Sianyde.header.start --> 
        <div id="header" class="center"> 
            <div id="header-image"> 
                <img src="/images/bg_header_01.jpg" class="first" alt="" /> 
                <img src="/images/bg_header_02.jpg" alt="" /> 
                <img src="/images/bg_header_03.jpg" alt="" /> 
                <img src="/images/bg_header_04.jpg" alt="" /> 
            </div> 
     
                </div> 
        <!-- Sianyde.header.end --> 
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Make sure that there is no empty lines before <?php tag. That can be the reason of issue, it seems session is not started.
  5. gungeuk

    gungeuk New Member

    Joined:
    Aug 13, 2010
    Messages:
    9
    Hi Alexander,
    I can confirm that there is no empty lines before this tag, it's set at line 1 with no spaces or empty lines
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Ok. Check session settings in aMember CP -> Version Info
    Then output phpinfo() from your header.php and make sure that session settings are the same exactly.

Share This Page