Page 1 of 1

Welcome, ***username here*** Code Help

Posted: Wed Feb 24, 2010 4:15 am
by devster
Hi all,

I have got my site up to a point where I'm quite happy with how it functions. I guess this is a more of a little feature than a necessity.

You know when you logon to a site and once logged on you get the "Welcome, John" or whatever name message somewhere, usually top left of the page. Can someone point me in the right direction with how to go about achieving this? I have the users setup on the MySQL database, the logon, logout all works swimmingly.

Thanks in advance for your help and advice.

Re: Welcome, ***username here*** Code Help

Posted: Wed Feb 24, 2010 4:29 am
by aravona
I just did this and got it working no errors using my session id as my users username. This is what I have.

echo "Welcome, ".$_SESSION['id'];

to call the persons name up.

Code: Select all

   
session_start();
include("connection.php");  
    
if (!empty($_SESSION['id'])) {
    echo "Welcome, ".$_SESSION['id'];
}
    else{
        // show login box 
}
This goes in my header file and will show the user log in box if there is no session 'id' in my case set. But you will need to tweak this, or your existing code, to fit it in, obviously using your own session variables and connections :)