Control visibility based on user logged in, etc.

Discussion in 'Customization & add-ons' started by chipmunk, Aug 30, 2006.

  1. chipmunk

    chipmunk New Member

    Joined:
    Aug 23, 2006
    Messages:
    3
    We'd like to add some things to templates (e.g. amember/templates/header.html) so that only logged in users can see them, or only users who have already purchased can see them. We used this code (found on the forum):

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

    Which is ok. However we can't get this part right:

    {php}
    if($logged_in)
    {
    Echo "<li><a href=\"" . ($config.root_url) ."/../logout.php\">log out</a></li>";
    Echo "<li><a href=\"" . ($config.root_url) ."/../member.php\">my account</a></li>";

    }
    else
    {
    Echo "<li><a href=\"" . ($config.root_url) ."/../login.php\">log in</a></li>";
    }
    {/php}

    We'd like to print the "root_url" variable, but don't know how to do that using the templates. In the exising code, we see that this works: {$config.root_url}, but that doesn't seem to work inside {php} tags. What's the proper way to do this?

    We tried the following:
    <pre>
    {php}
    var_dump(get_defined_vars());
    {/php}
    </pre>
    and it dumps a lot of variables, we just can't access them. We would like to know how we can get to stuff like "member"/"member_id", etc either from code within the {php} tags, or just in {if ...} tags.

    Thanks in advance!
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    $config.root_url
    - replace to
    $GLOBALS['config']['root_url']

Share This Page