Session variable disappears
I have a problem with a session variable that just disappears when i navigate to a new page. On page a the variable works all the way. I have made several outputs of it from start to finish.
On page B it is gone and page b looks like this:
<?php
session_start();
//include "dbConnect_local.php"; // Databasanslutningen lokalt
//include "dbConnect.php"; 开发者_JAVA百科 // Databasanslutningen web
echo $_SESSION['coming_from_input']." apa";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sv" lang="sv" >
<head>
</head>
<body>
</body>
</html>
Page b is on the same domain as page a. And this is all code, nothing is sent before session_start();
Using session_id() I can see that the session id is different on the two pages.
Thanks for any help
You do have a session_start(); on page A before everything else, don't you?
If so, post page A too, because we have too few info...
You do have a session_start(); on page A before everything else, don't you?
...and you've checked your logs to see that no errors were reported?
And you've created a script which explicitly thows an error to check you're logging is working correctly?
And you've looked that the HTTP response headers to ensure that the cookie is being set by the server on page A?
And you've looked at the HTTP request headers to check that the cookie is being returned by the browser?
And you're using the default session handler?
And you've checked that the session file directory is writeable by the webserver uid?
And you've checked that after hitting page A a session file is created in that directory with the expected content?
...only you didn't say in your original post.
Ok so I have solved this now and it seems to be my stupid webhotel that is screwing things up for me. I wrote this as an answer and not as a comment so that everyone could see it. I did like this:
I wrote out the session id on page a and page b. They did not have the same value. That's weird I thought, since it works in another part of my page(login and register). So i logged in and from the register page I jumpt directly to page B from this issue. Id:s were matching.
Ok funny, so I removed all code that wasn't needed from page a. When I now tried everything worked. Good, I added code chunk by chunk and ran the code in the browser all the time, this to see when it stopped working.
When I had added all previously removed code... it was still working!!
I have no idea how it came to be like this but my guess is that it's the webhotell screwing things up for me. Had a talk with them the other day related to other issues and it seemed like they cache files on the server so when I upload new files I could not see the results until 10minutes later, and by that time I had done another 10 or 15 uploads......
精彩评论