Print Login Name On Php Or Html Pages

Discussion in 'Customization & add-ons' started by tomarriola, May 4, 2003.

  1. tomarriola

    tomarriola Member

    Joined:
    Mar 29, 2003
    Messages:
    140
    Hello,
    I'd like to have my registered users' login name print on some of the pages they are access. These are a mix of php and html files. What is the syntax to make this happen? Thanks
    Tom
  2. Mark Hogan

    Mark Hogan Guest

    If you can do includes, I put the following in my html page:

    <!--#include virtual="/amember/name.php" -->

    Here is my name.php:

    <?php
    session_start();
    if ($_SESSION['_amember_user']['login'] > '')
    {
    echo " ";
    echo $_SESSION['_amember_user']['name_f'];
    echo " ";
    echo $_SESSION['_amember_user']['name_l'];
    echo " (";
    echo $_SESSION['_amember_user']['login'];
    echo ")";
    }
    ?>
  3. tomarriola

    tomarriola Member

    Joined:
    Mar 29, 2003
    Messages:
    140
    Thanks!
    tom
  4. tomarriola

    tomarriola Member

    Joined:
    Mar 29, 2003
    Messages:
    140
    The above didn't quite do what I want. let me give more details. members get access to a form where they can post comments. the cgi script gathers their ip, referrer and username to print on the html page (I can make this a php page if needed)

    Here is the line from the cgi script that gathers the info:
    $input = "<!--COMMENT-->" . "n<!--Posted using: $ENV{'HTTP_USER_AGENT'}-->n" . "n<!--Posted by: $FORM{'user'}-->n" . "n<!--From: $ENV{'REMOTE_HOST'}-->n" . "n<!--At IP address: $ENV{'REMOTE_ADDR'} -->n" . "<BR clear=all>" ."<HR>" . "$time" . "<P>n" .$input;

    With my previous system I was able to get the username with the statement:
    $FORM{'user'}

    What is the equivilant with the amember system?
    Thanks
    Tom
  5. alex-adm

    alex-adm Guest

    <?
    //user must be authorized in aMember when he access this page
    session_start(); // need to be called once
    print $_SESSION['_amember_user']['login'];
    ?>
  6. tomarriola

    tomarriola Member

    Joined:
    Mar 29, 2003
    Messages:
    140
    When I try that i get this error msg:

    Warning: Cannot send session cache limiter - headers already sent (output started at /home/sites/site3/web/case2/comments.php:13) in /home/sites/site3/web/case2/comments.php on line 20

    What can I do?

    My goal is that when folks post a comment with my cgi script that their username will be printed on it automatically.

    Tom
  7. alex-adm

    alex-adm Guest

    The php_include code must be VERY TOP on the page. There shouldn't be any text or spaces before it.
  8. jcary

    jcary Guest

    Hey Alex,

    Let me see if I understand this correctly:

    I save the php code you provided as (let's say) name.php. Then in order for it to show up without the error message, the php include code to call the name.php file needs to be at the top of the html page? Can it be placed anywhere else on the page so on the top of the body text, it can say, "Hello [name]" etc.?

    Thanks.

    Josh
  9. tomarriola

    tomarriola Member

    Joined:
    Mar 29, 2003
    Messages:
    140
    problem solved. In case anyone else needs to do the same I outlined my problem and solution below.

    Here was what I am trying to do:

    1-Setup an amember protected form for posting text to a web page.

    2-A cgi script gathers the content of the form and prints it to the web page.

    3-The cgi prints the date, time and ip address along with the content of the form.

    4-As each user logs on he adds to this web page by posting comments.


    Here was the solution:

    STEP ONE
    I made it work by adding this to the top of the page that has the form to collect comments:

    <?
    //user must be authorized in aMember when he access this page
    session_start(); // need to be called once
    print $_SESSION['_amember_user']['login'];
    ?>

    STEP TWO
    On the page that has the form to collect comments I also put a hidden form field in as follows:

    <INPUT TYPE=hidden NAME=name VALUE="<?php
    {
    echo $_SESSION['_amember_user']['login'];
    }
    ?>">


    STEP THREE
    Then in the cgi script I added this tag to make it print on the web page:

    <!--Posted by: $FORM{'name'}-->

    And it worked.

    Thanks
    to all for the help.

    Tom

Share This Page