$_POST[username]??

Discussion in 'PHP' started by nodnil, Dec 3, 2008.

  1. #1
    Hello, I am having some troubles with my PHP page.

    I have the user log in, and then I want it to say at the top of each page "Hello, <username>" but I am unsure on how to go about it. I was thinking maybe
    print " Hello " . $POST_[username] . ".";
    Code (markup):
    But on second thought, wouldn't that only work for one page?

    Would something to do with sessions work?


    Thanks for your replies, nodnil.
     
    nodnil, Dec 3, 2008 IP
  2. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #2
    
    $a=$POST_[username];
    $b="Hello".$a;
    echo $b;
    
    PHP:
    that's it..
     
    Freewebspace, Dec 3, 2008 IP
  3. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    In this case, you cannot use $_POST to show the username in EVERY pages.
    You will have to call the cookie (or session, it depends on your login page).
     
    djzmo, Dec 3, 2008 IP
  4. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #4
    you need cookie or session for doing this...
    try this code
    after you get your $_POST['username'];
    don'f forget call session function
    session_start();
    $_SESSION['username'] = $_POST['username'];
    PHP:
    if you need call your username session on each page, you can do this
    session_start();
    $username = $_SESSION['username'];
    echo 'Welcome back '.$username;
    PHP:
     
    misbah, Dec 3, 2008 IP
  5. nodnil

    nodnil Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    Thanks I will give it a try.
     
    nodnil, Dec 3, 2008 IP
  6. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Use session.

    BTW your $POST_ should be $_POST
     
    ads2help, Dec 4, 2008 IP