Having Problem with My Session Code

Discussion in 'PHP' started by ivenms, Aug 7, 2007.

  1. #1
    I have some problem with session code.

    On one page I registered the session with the following code:
    
    session_register("username");
    
    PHP:
    After that without destroying it, when I check the session with the code:
    
    if(session_is_registered('username'))
    
    PHP:
    It gives FALSE

    What is the error on here?

    Please help.

    If there any better technique available for establishing session?
     
    ivenms, Aug 7, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Did you start the session before you registered any variables. Some servers wont properly initialize a new session.

    Try
    session_start();
    session_register("username");
     
    jestep, Aug 7, 2007 IP
  3. ivenms

    ivenms Peon

    Messages:
    334
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes....

    The code is on there. But the problem still existing.

    Is it necessary to add:

    session_start();

    before:

    if(session_is_registered('username'))
     
    ivenms, Aug 7, 2007 IP
  4. ivenms

    ivenms Peon

    Messages:
    334
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorryy.........

    I solved the problem.

    I missed the session_start() on the second page. Now solved the problem. Thanks for helping me.

    Thanks....
     
    ivenms, Aug 7, 2007 IP
  5. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #5
    yes session_start() is most important to start session variable..
     
    AdnanAhsan, Aug 8, 2007 IP