View Full Version : Logged in / out message????

03-29-2007, 09:04 PM
Hi i have my site.

at the top i want it to say ' Welcome Guest, Login / Register! ' if the user is not logged in and if they are ' Welcome "$_SESSION['MM_Username'];", Logout! '

How is this done?????

03-29-2007, 09:10 PM
Wow thats vague.

If ( user_is_logged_in) {
echo "Welcome username";
} else {
echo "Welcome Guest";

Not much more I can give you without your code your using.

03-29-2007, 09:13 PM
i dont have any?!?

i may be able to do it my self

how do you check if a session exists????

03-29-2007, 09:14 PM
Something along these lines:

if( isset( $_SESSION['MM_Username'] ) )
echo 'welcome/logout';
echo 'register';

It would probably be a better idea to have some sort of function to check whether a user is properly logged in though, like iLLin here mentioned.

03-29-2007, 09:15 PM
Here ya go sessions (http://us2.php.net/manual/en/ref.session.php)

03-30-2007, 05:33 AM
At the top of you're page you'll need to have a:


That begins the session on the page. Next, we need to gather any session information we have. The following code will gather the username / password of the user browsing your page, assuming that they have one.

$username = $_SESSION['username'];
$password = $_SESSION['password'];

Next, we put that information to use to determine whether the person is logged in, or a guest. You could do something like:

if(!$username && !$password) {
echo "You're a guest";
} else {
echo "Welcome back $username.";

This was my first post here, hope I've been helpful.

03-30-2007, 05:40 PM

And welcome to coding forums! :)