Problem regarding session..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas1111
    New Member
    • Feb 2008
    • 122

    Problem regarding session..

    Hi All..

    I want to display who has logged in ...Like Logged in as "_______"..
    or like the one on the top left corner of your screen.... Hello, xxxxx
    For that i have included the following code in my loginpro page..

    [PHP]

    session_start() ;
    include("sessio n.inc.php");

    if (login($_POST['txtname'],$_POST['txtpass']) == TRUE)
    {
    session_registe r("username") ;
    $_SESSION['username'] = $_POST['txtname'];
    }

    [/PHP]


    In the other pages i have written this code

    [PHP]

    <?php
    include("sessio n.inc.php");
    Logged in as :<?php echo $_SESSION['username']; ?>
    ?>
    [/PHP]

    I am not able to display The login Name ..

    How can i solve it???
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Did you forget the session_start() in the second page?

    By the way, the use of the session_registe r() function is deprecated as of PHP 4.1.0.
    You should just add elements to the $_SESSION array.

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      Yeah, session_start() on the second page is all I can see. To follow on from Alti, you should just remove the line to register the variable:

      [PHP]
      ... { session_registe r("username") ; } //Remove this!
      $_SESSION['username'] = $_POST['txtname'];
      }
      [/PHP]

      Comment

      • vikas1111
        New Member
        • Feb 2008
        • 122

        #4
        Thanks for both of you..

        I removed register and included session start().. Now its working..

        Comment

        Working...