...

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



the-dream
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?????

iLLin
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.

the-dream
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????

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



if( isset( $_SESSION['MM_Username'] ) )
{
echo 'welcome/logout';
}
else
{
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.

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

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


session_start();

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.

the-dream
03-30-2007, 05:40 PM
Thanks!

And welcome to coding forums! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum