Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Logged in / out message????

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

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Wow thats vague.

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

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

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    i dont have any?!?

    i may be able to do it my self

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

  • #4
    New Coder
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 1 Time in 1 Post
    Something along these lines:

    PHP Code:
    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.

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here ya go sessions

  • #6
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    At the top of you're page you'll need to have a:

    PHP Code:
    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.

    PHP Code:
    $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:

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


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

  • #7
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Thanks!

    And welcome to coding forums!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •