PHP session data not saved

I have one of those situations that I swear that I did not touch the server. I honestly did not touch any php script. The problem I am facing is that php data is not stored on different pages or page updates. I know that a new session is created correctly because I can set a session variable (for example, $ _SESSION ['foo'] = "foo" and print it back on one page very well. But when I try to use the same variable on another it is not installed on the page! Are there any php functions or information that I can use on my host server to find out what is happening?

Here is an example script that is not working on the server of my hosts at the moment:

<?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views']+ 1; else $_SESSION['views'] = 1; echo "views = ". $_SESSION['views']; echo '<p><a href="page1.php">Refresh</a></p>'; ?> 

The variable 'views' will never increase after the page is refreshed. I think this is a problem on their side, but I wanted to make sure that at first I was not a complete idiot.

Here is phpinfo () for my host server (PHP Version 4.4.7): alt text

+55
php session
01 Oct '08 at 1:57
source share
22 answers

Thanks for all the helpful info. It turns out that my host changed the servers and started using a different session saving path, other than / var / php _sessions, which was no longer there. The solution would be to declare ini_set(' session.save_path','SOME WRITABLE PATH'); in all my script files, but that would be a pain. I talked with the host and they explicitly set the session path to the real path that really existed. Hope this helps anyone with a session problem.

+41
01 Oct '08 at 21:57
source share

Make sure you do not mix https: // with http: //. Session variables do not propagate between secure and insecure sessions.

+11
Oct 25 2018-11-11T00:
source share

With the same problem - what happened to me, our server administrator changed session.cookie_secure boolean to On, which means that cookies will only be sent through a secure connection. Since the cookie was not found, php each time created a new session, so the session variables were not seen.

+8
11 Oct. '10 at 16:16
source share

Use phpinfo() and check session.* Settings.

The information may be stored in cookies and your browser does not accept cookies, something like this.

Check it out and come back with the results.

You can also do print_r($_SESSION); to have a dump of this variable and see the contents ....

As for your phpinfo() , is session.save_path valid? Is your web server accessible to this directory?

Hope this helps.

+7
01 Oct '08 at 2:04
source share

I had the following problem

index.php

 <? session_start(); $_SESSION['a'] = 123; header('location:index2.php'); ?> 

index2.php

 <? session_start(); echo $_SESSION['a']; ?> 

The variable $_SESSION['a'] was set incorrectly. Then I changed index.php accordingly

 <? session_start(); $_SESSION['a'] = 123; session_write_close(); header('location:index2.php'); ?> 

I don’t know what this internally means, I just explain to myself that changing the session variable was not fast enough :)

+6
Jul 21 2018-11-21T00:
source share

Verify that the web server saves the session save path.

Make sure you have cookies. (I forgot when I turned them off to check something)

Use firefox with the firebug extension to check if a cookie is set and transmitted.

And on an unrelated note, start looking at php5 because php 4.4.9 is the last of the php4 series.

+5
01 Oct '08 at 2:23
source share

Check which group and owner are in the folder where the script is running. If the group ID or user ID is incorrect, for example, set to "root", this will lead to incorrect saving of sessions.

+3
Apr 11 '10 at 9:15
source share

Check the value of "views" before increasing it. If for some bizarre reason it is set to a string, then when you add 1 to it, it will always return 1.

 if (isset($_SESSION['views'])) { if (!is_numeric($_SESSION['views'])) { echo "CRAP!"; } ++$_SESSION['views']; } else { $_SESSION['views'] = 1; } 
+2
Oct 01 '08 at 2:06
source share

Well, we can eliminate the code error because I checked the code on my own server (PHP 5).

Here's what to check:

  • Are you calling session_unset () or session_destroy () anywhere? These functions immediately delete session data. If I put them at the end of my script, it will start behaving the way you describe.

  • Does it work the same in all browsers? If it works in one browser and not in another, you may have a configuration problem in a non-functioning browser (i.e. you have disabled cookies and forgot to enable them or blocked cookies by mistake).

  • Is the session folder writable? You cannot test this with is_writable (), so you will need to navigate to the folder (from phpinfo () it looks like / var / php _sessions) and make sure that the sessions are actually created.

+2
01 Oct '08 at 4:36
source share

I know one solution that I found (OSX with Apache 1 and just switched to PHP5) when I had a similar problem, was that disabling 1 specific key (i.e. unset ($ _ SESSION ['key ']);) did not cause him to save. As soon as I have not canceled this key, it is no longer saved. I never saw this again, except for this server on another site, but then it was a different variable. There was nothing special.

Thanks for that Darryl. It helped me. I deleted the session variable, and for some reason it did not allow the session to complete transactions. now I just install it instead of null (which works great for my application) and it works.

+2
Jun 30 '09 at 21:50
source share

If you establish a session in php5, try reading it on the php4 page, it may not look in the right place! Make the pages the same php version or set session_path.

+2
Apr 10 '10 at 14:50
source share

I spent years searching for an answer to a similar problem. This is not a problem with code or customization, since very similar code worked fine in another .php on the same server. It turned out that the problem was caused by a very large amount of data that is stored in the session on this page. In one place we had this line: $_SESSION['full_list'] = $full_list where $full_list was an array of data loaded from the database; each row was an array of approximately 150 elements. When the code was originally written a couple of years ago, the DB contained only about 1000 lines, so $full_list contained about 100 elements, each of which was an array of about 20 elements. Over time, 20 elements turned into 150 and 1000 rows, turned into 17000, so the code stores about 64 megabytes of data in a session. Apparently, while storing this amount of data, he refused to store anything else. After we changed the code to process the data locally without saving it in the session, everything worked fine.

+2
Jun 21 '11 at 16:32
source share

I know one solution that I found (OSX with Apache 1 and just switched to PHP5) when I had a similar problem, was that disabling 1 specific key (i.e. unset ($ _ SESSION ['key ']);) did not cause him to save. As soon as I have not canceled this key, it is no longer saved. I never saw this again, except for this server on another site, but then it was a different variable. There was nothing special.

+1
Oct. 01 '08 at 5:52
source share

Here is one common problem that I have not seen in other comments: does your host have any cache? If they automatically cache the results in some way, you will get this behavior.

+1
01 Oct '08 at 7:18
source share

Just wanted to add a little note that this could also happen if you accidentally missed the session_start () statement on your pages.

+1
May 31 '09 at 14:11
source share

I had a session cookie path set to "//" instead of "/". Firebug is awesome. Hope this helps someone.

+1
Jul 12 2018-11-11T00:
source share

I had this problem when using secure pages that sent me from www.domain.com/auth.php, which redirected to domain.com/destpage.php. I removed www from the auth.php link and it worked. It left me because everything worked differently; The session was not established when I arrived at my destination.

+1
Jan 12 2018-12-12T00:
source share

A common issue that is often overlooked is that there should not be any other code or extra interval before the session_start () command.

I had this problem before where I had an empty line before session_start (), due to which it did not work properly.

+1
Jun 20 2018-12-12T00:
source share

edit php.ini I think the value of session.gc_probability is 1, so it is set to 0

session.gc_probability = 0

+1
Sep 23 '12 at 18:01
source share

Adding my solution:

Check access to the correct domain . I used www.mysite.com to start a session, and tried to get it from mysite.com (without www ).

I solved this by adding htaccess interception of all domains on www to be on the safe side / site.

Also check if you are using http or https.

+1
03 Oct '14 at 2:35
source share

Check if you are using session_write_close (); anywhere, I used it right after another session, and then tried to write to the session again, and it didn’t work .. so just comment that sh * t out

0
Jul 31 '09 at 11:43
source share

A few more things that I had to do (I had the same problem: the lack of saving sesson after updating PHP to 5.4). You do not need this, depending on your php.ini server (check phpinfio ());

 session.use_trans_sid=0 ; Do not add session id to URI (osc does this) session.use_cookies=0; ; ensure cookies are not used session.use_only_cookies=0 ; ensure sessions are OK to use IMPORTANT session.save_path=~/tmp/osc; ; Set to same as admin setting session.auto_start = off; Tell PHP not to start sessions, osc code will do this 

Basically, your php.ini should be set to not have cookies, and the session settings should match what osc wants.

You may also need to modify several fragments of the session code in the application_top.php application - creating objects in which nobody is in the tep_session_is_registered (...) calls (for example, a navigation object), set the $ HTTP_ variables for the new $ _SERVER and several other isset tests for empty objects (google for information). I ended up being able to use the session.php source files (including / classes and includes / functions) with a slightly modified application_top.php to get started again. Php.ini settings were the main problem, but it, of course, depends on what your server company installed by default.

0
04 Oct '14 at 10:29
source share



All Articles