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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devster
Forum Newbie
Posts: 2
Joined: Fri Feb 12, 2010 4:05 am

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

Post 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.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

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

Post 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 :)
Post Reply