Session are creating problem

Discussion in 'PHP' started by babaMBA, Jun 3, 2007.

  1. #1
    I will register a session after checking that username and password is valid by method

    <?php
    session_register(username);
    ?>

    If in my php.ini file register_globals are on then on any page of my website if i use

    <?ph
    echo ("Session is registered as : $username");
    ?>

    it will show the username of the user loged in like "admin"

    but if in my php.ini file register_globals are off then it register the session butwhen i try to use

    <?ph
    echo ("Session is registered as : $username");
    ?>
    it will not show the "admin" or the username of the user that is logged in.

    i want to show "welcome User" to my pages and i want this with register_global off.

    Plz help me how can i solve my problem
     
    babaMBA, Jun 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Don't use session_register(). Do:
    
    $_SESSION['username'] = 'Admin';
    
    PHP:
    And in your next page:
    
    echo ("Session is registered as :".  $_SESSION['username']);
    
    PHP:
     
    nico_swd, Jun 4, 2007 IP
  3. babaMBA

    babaMBA Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If I use $_session['username'] = 'Admin' ;

    Then is it do the same function of registraing the session , I use session_register() for registrating my session. Is this

    $_session[] is also used for registrating session.


    The second thing is the user is not alway admin , the username is one that the user use at login page.

    If user use admin then i want to register my session "admin" if user enter username "baba" then i want to register my session "baba".

    How can i do that.
     
    babaMBA, Jun 4, 2007 IP
  4. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Write

    extract($_SESSION);

    at begin lines.
     
    jitesh, Jun 4, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Seems too obvious but is this all you need?:
    echo "Session is registered as : {$_SESSION['username']}";
    PHP:
     
    krt, Jun 4, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    From php.net:
    www.php.net/session_register
     
    nico_swd, Jun 4, 2007 IP