I've got a login script that works fine and I'm trying to interface it with a message board program. For some reason my session variables don't pass. I put session_start(); at the top of every page, I registered the session variables like this

session_register["somestuff"];
$_SESSION["somestuff"] = $somestuff;

when I try and call $SESSION["somestuff"] it's empty.

help...

thanks

    session_register("somestuff");

    not
    session_register["somestuff"];

    $_SESSION["somestuff"]

    not
    $SESSION["somestuff"]

      yeah, I kinda messed up with that post. I have gone back through and checked and recjecked all of my syntax. It is perfect now. I don't know why it won't work.

      The the session variable will pass to one page but I can't get it to go to next. So if I register it on one page and then call it on the next page it works but if I try and call it on another page after that it fails

      any ideas?

        session_register() is not needed anymore in recent php version, you simply start the session, register values with
        $SESSION['something'] = "your value" and access it the values as
        $
        SESSION['something'].

        apart from that, I don't think you'll get around posting some code. if it is a lot, cut it down to the minimum that exposes the problem. and don't forget to put the [php] tags around it, it is easier to read then.

          Alright...I'll try to simplify this so let's assume a user is already in the database. There is the page where they log in. That get's posted to another page that checks their info against the database and if it passes it registers the session variables like this:

          $_SESSION["userid"] = $userid;
          $_SESSION["passwd"] = $passwd;
          

          then it prints a link to the forum which happens to be named index.php which checks to see if the session is registered. I'll giv you the beginning of index.php and the function

          <?php
          session_start();
          require( './functions.php');
          checksession($_SESSION["userid"]);
          showheader("noiseusse bored");
          ?>
          

          here's the checksession() function from functions.php:

          <?php
          function checksession($anyuser)
          {
          	if ($anyuser == "")
          	{	
          		showheader("error");
          		?>
          		<html>
          		<head>
          		<center>
          		you must <a href="home.php">login</a> in order to be here.
          		</center>
          		<?php
          		showfooter();
          		exit();
          	}
          }
          

          That works fine, the session variable remains but on any subsequent page, like if I wanted to view the posts, the session variable doesn't go. I'm calling the checksession() function on every page to prevent people from seeing anythig if they aren't logged in.

          So, just to make it extra clear: After getting to the index.php page without a problem I want to view posts. I click on a topic id and it takes me to view.php which looks like this:

          <?php
          session_start();
          
          require( './functions.php3');
          checksession($_SESSION["userid"]);
          viewpost($topicID);
          ?>
          

          At that point the session variable is empty and so my error checking tells me I need to log in.

          I hope that was clear enough, thanx for all your help

            okay, what I'd do:
            carefully check that you call session_start on all pages.

            then monitor what's going on in your session folder (usually tmp on linux, on windows you can look it up in the php.ini file).

            is the problem that the session value actually is dropped (then you'd see on of the text files changing)?

            if not, probably the session id (this unique string that identifies the session and is either stored in a cookie or appended to the url) is getting lost, and therefore the data is still there, but cannot be mapped to the session anymore.

              OK...I figured it out. I'll explain in case it's helpful to anyone else.

              My code was perfect. I checked it abou 5 million times so I figured it must be something "cosmic" about php that I din't understand. I tried out a few things but here's what worked.

              I was registering session variables like this

              session_register("userid");
              $_SESSION["userid"] = $userid;
              

              looks fine right? wrong. The session variable I am assigning a value to has the same name as the variable I'm assigning to it.

              so I did this:

              session_register("userid_ses");
              $_SESSION["userid_ses"] = $userid;
              

              that's it, I just changed the name and now it works. So the moral of the story is always have unique names for your session variables otherwise you will end up crying.

                Write a Reply...