1

Earlier today I posted this question: $_SESSION variables and id do not carry over between pages on localhost Because I believed that the Session was not persisting between pages. The question didn't get much answers and I was playing around witht hte script all day and I discovered that if I do this:

$_SESSION['UID'] = $id;
session_id($sessID);
echo session_id();

//session_write_close();
//header("Location: /accountwebsite/landing.php");
//exit();

I prevented the redirect to see where the problem begins (i.e. where does the session reset) and I noticed that although the echo statement does output the correct ID, once the script is done running, and I am still on the same page, if I head over to Firefox options and take a look at cookies, the session id is reset to the generic one. As in, on my script I set it to a special token I generate, and yet at the end of the script, the id is set back tot the original set by PHP. I headed to the folder where XAMPP saves the session files, and a file for my personally set id was there and so was the php generic id one.

What reasons could the session have to reset at the end of the script? I would appreciate any help, I've been working on this for the past 3 days and it seems like such a noobish problem to have.

EDIT:

I don't believe my question is the same as the other, because that one has a change/loss of session between pages, whereas my script removes the session variables at the end of the very script it runs on without an additional session_start() or any unsetting of the session. My session save folder has permissions because I have seen the files written to it. My browser does allow for cookies because as I mentioned earlier, I saw the value fof the sesssion id in the firefox options>privacy tab.

EDIT 2:

In the linked question, the user says that their issue was on the hosting service's end, and they had not set a path for the session's files to be saved. I have already stated that my save path is set and I am running this locally on XAMPP, so my problem is entirely different since it still occurs.

EDIT 3:

The solution to Arihant's problem is completely different, therefore it has to be a different problem. I only made this post because I realize my problem is actually not what I thought it was this morning when I posted it. I haven't encountered this problem anywhere else on the internet, everyone's issue is loss of session between pages not on the same page, and

I have also triple checked all of the fixes I found online. Both php scripts begin with session_start() so that I am sure nothing is sent before that function is called. I have set a tmp directory for the session and it works. Cookies are enabled on my browser. register globals is off. the redirection is to the same domain.

I even checked if my file had an invisible Byte-order mark that would count as the data sent before the session_start() call and there is none in my whole document making that function the first thing that is called. I have been working on this problem for 3 days now and I cannot move forward. I have literally tried everything.

I realize that since I don't know what the reason for the actual problem is my question seems identical to many others, but I have tried all the solutions on those threads and I still have no positive results and therefore this is not a duplicate.

Community
  • 1
  • 1
hsbsid
  • 301
  • 1
  • 2
  • 10

0 Answers0