0

I'm developing a site for someone where users can post problems to a website and the Admin of the company can view the problems and give a solution for it. I use one page that takes care of the login handling and a mysql db. The problem is that i can log in, it shows me another panel(userpanel), but whatever other button i click, it takes me back to the login panel. It used to work as i was able to post data to my database. but suddenly after some changes on my website, it stopped working (and i can't find the problem anymore.)

When i log in, $_SESSION["LoggedIn"] gets a value and goes to the other panel on the same page with http post. when i click a button there, it seems that $_SESSION["LoggedIn"] is removed again because i check with isset if the user is logged in, otherwise it shows the userpanel.

//check user logged in
if (isset($_SESSION['LoggedIn'])) {

//Problem posted
if (isset($_POST["plaatsen"])) {
    //Processing - plaatsen
    postProblem();
    }
} else {
//do login thing

}

I've attached my code here and i hope anyone can help me out.

Index.php: http://pastebin.com/BZSirUTT

Functions.php: http://pastebin.com/7Hknhm9r

Website: http://php.olvgroeninge.be/~sac.26A-07/php/Oefeningen/Oefening3/index.php (it's in dutch)

4

1 回答 1

4

Sessions typically don't disappear by themselves. If they do, assuming you did run session_start() first, it can be due to:

  1. The session could not be saved on the server; this can be due to disc space or permission issues. It could also be due to any page output before the session_start() statement. Fortunately, you can see this by heightening the error reporting at the start of your script:

    ini_set('display_errors', 'On'); error_reporting(-1);

  2. The session could not be found; for session to perpetuate it requires the session id at every request. Depending on your settings, this can come from the URL (PHPSESSID=xxx) or cookies. In the latter case, you can verify that your browser sends the cookie by whipping up the browser developer tools.

  3. You destroyed the session yourself; calling session_unset or session_destroy will clear and remove the session respectively. Make sure this doesn't happen accidentally.

  4. The session is garbage collected; this normally only happens after some time of inactivity, configured using the relevant ini settings

  5. The session could not be read; just like #1 but for reading.

Hope at least one of these points helps you.


Debugging the session

You can add the following code to all pages to isolate the problem:

echo '<pre>', htmlspecialchars(print_r($_COOKIE, true)), '</pre>';
session_start();
echo '<pre>Session = ', session_id(), '</pre>';

Update The problem is that the index.php doesn't set any cookies; OP created a separate small test page which does set cookies. Turns out the problem is #2 then :)

于 2012-06-10T15:41:42.030 回答