Results 1 to 3 of 3

Thread: [RESOLVED] Session problem php5

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Resolved [RESOLVED] Session problem php5

    hi all,
    i have a problem of session in php5

    in my first page i have this code

    Code:
    <?php
    session_start();
    //Some code here
    
    $_session['User_Logged']="Yes";
    
    ?>
    and in my other page i want to read the session variable to know if the user is logged in or not
    Code:
    <?php
    session_start();
    
    if($_session['User_Logged']!="Yes") 
    {
    	echo "You are not logged in."
    	exit();
    }
    
    //Some Actual Working HERE
    ?>
    but i get an error in the red line above

    Undefine Index User_Logged

    this code has worked fine for me in php4 before
    pls help

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Session problem php5

    The first problem with that code is you have missed a semicolon off the echo line:

    PHP Code:
    echo "You are not logged in."
    The second problem is, when using the SESSION array, it should always be in capital letters not lowercase as you have coded it.

    Like this:

    PHP Code:
    <?php
    session_start
    ();
    //Some code here

    $_SESSION['User_Logged']="Yes";

    ?>
    PHP Code:
    <?php
    session_start
    ();

    if(
    $_SESSION['User_Logged']!="Yes"
    {
        echo 
    "You are not logged in.";
        exit();
    }

    //Some Actual Working HERE
    ?>
    That's why you got 'undefined index' error because PHP thinks you have declared an ordinary array called $_session, which of course won't persist to your second page.
    Chris

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: Session problem php5

    sorry.
    it was my mistake because i wrote this code in notepad.
    thank you so much it is solved.

Posting Permissions

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



Click Here to Expand Forum to Full Width