This has really been confusing me. I have my php script set up to take the user ID out of the database, and put it into a session variable, however.. This will only work as long as I navigate through one directory.

i.e user/index.php --> user/account.php holds the info, but user/index.php --> account/index.php gives me this error:

"Notice: Undefined index: user_id in (host root dir)/account/index.php on line 14"

Now for the code..

Function that sets the info for $_SESSION['user_id']:

function getId()
}

$email = $_POST['txtEmail'];
$password = $_POST['txtPassword'];

$sql = "SELECT login_id
	   FROM tbl_login 
	   WHERE login_password = ('$password') AND login_email = ('$email')";

	$result = mysql_query($sql);
	$row = mysql_fetch_assoc($result);
	$_SESSION['user_id'] = $row['login_id'];
{

user/library/functions.php - holds the getId() function.
user/login.php - calls the function and registers the session.
user/account/index.php - tries to get the session info but fails (yes I put session_start() before I called the info) "Notice: Undefined index: user_id in (host root dir)/account/index.php on line 14"

The wierdest thing is about this, is that when I go back to user/login.php to check if the session is registered or not, it says that it is. But then I go back to account.php and of course its not.. stays this way till I unregister.

like I said.. if I keep in in the same directory everything runs fine. As far as I understand sessions are supposed to retain data no matter which directory you are on as long as staying in the root dir (or untill you unregister/close browser).

Anything helps. My main goal is to be able to hold this login_id info from 'blahblah/var.php' to 'blahblah/anything/var.php' Thank you very much in advance.

    Let's take a look at how sessions are set up on your server.

    Sometime in your script after you call [man]session_start/man to open the session, insert this code:

    print_r(session_get_cookie_params());

    Let us know what it says.

      Thank you for your reply brad, here is the info that returns:

      Array ( [lifetime] => 0 [path] => / [domain] => [secure] => )

        Okay, let's make sure we're getting the same SID each time.

        On the login.php page (where it first sets the variable), add this code AFTER you set the session variable in question:

        echo 'Current SID: ' . SID . '<br>Debug: ' . print_r($_SESSION);

        Place the same code into account/index.php as well (AFTER the call to session_start()).

          Results:

          Login.php after registering session:

          Array ( [user_id] => 67 ) Current SID:
          Debug: 1

          Account.php:

          Array ( ) Current SID:
          Debug: 1

          Thanks again. See what I mean though? It will not read the info if I change the directory.. seems so odd to me.

            Er, it should have returned a SID though...

            Okay, in a separate test script, do a phpinfo() and scroll down until you find the 'sessions' table. Paste that entire table in here.

              Alright. I've never seen that path used for save_path... is this a Unix server? If so, why not use something like /tmp ?

              I'm not sure if this is the issue or not... it doesn't seem likely, but then again who knows.

              Do you have AOL Instant Messenger or Yahoo Instant Messenger?

                I can install AIM temporarily sure, I will PM you my screen name, and thanks.

                  It is setting the session save path as relative to the current dir '.\' so when you change dir it looks in the wrong place. Needs to be changed for the sever as a whole I should say, otherwise is will keep on tripping people up.

                    Yup, that's the conclusion we reached on AIM a few minutes ago. Why I didn't realize it was using a relative path... I have no clue. I even looked at that path for a while and wondered what was odd about it! 🙁

                    Anyway, I believe we resolved it, I'm just waiting on him to finish up configuring/testing it out to make sure everything's running smoothly.

                    EDIT: By the way, Roger, did you ever receive my PM?

                      Yes, I did, and I still say that the manual sez that nothing will be executed in the ELSE if you omit the braces IN THE ELSE, regardless of what happens in the IF. There is a user note that makes the same point if you care to read it in the manual.

                        Well my host (www.ixwebhosting.com) only allows permenant php setting changes on linux platforms, so I had to recode all the pages that use sessions to call my "config" page with the added code:

                        ini_set("session.save_path", "");

                        Thank you again guys. You went out of your way to help me out and I appreciate that brad.

                        Everything works well now, consider this Resolved.

                          Write a Reply...