tags:

views:

5958

answers:

13
+2  A: 

Hi!

use phpinfo() and check the session.* settings.

Maybe the informations is forced to be stored in cookies and your browser do not accept cookies, something like that.

Check that first and come back with the results.

You can also do a < pre>print_r($_SESSION);< /pre> to have a dump of this variable and see the content....

Regarding your phpinfoI(), does the session.save_path is a valid one? Does your webserver has write access to this directory?

Hope this helps.

vIceBerg

vIceBerg
A: 

Check the value of "views" when before you increment it. If, for some bizarre reason, it's getting set to a string, then when you add 1 to it, it'll always return 1.

if (isset($_SESSION['views'])) {
    if (!is_numeric($_SESSION['views'])) {
        echo "CRAP!";
    }
    ++$_SESSION['views'];
} else {
    $_SESSION['views'] = 1;
}
nickf
+2  A: 

Check to see if the session save path is writable by the web server.

Make sure you have cookies turned on.. (I forget when I turn them off to test something)

Use firefox with the firebug extension to see if the cookie is being set and transmitted back.

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

DGM
A: 

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

Here's what to check for:

  1. Are you calling session_unset() or session_destroy() anywhere? These functions will delete the session data immediately. If I put these at the end of my script, it begins behaving exactly like you describe.

  2. Does it act the same in all browsers? If it works on one browser and not another, you may have a configuration problem on the nonfunctioning browser (i.e. you turned off cookies and forgot to turn them on, or are blocking cookies by mistake).

  3. Is the session folder writable? You can't test this with is_writable(), so you'll need to go to the folder (from phpinfo() it looks like /var/php_sessions) and make sure sessions are actually getting created.

Nathan Strong
A: 

I know one solution I found (OSX with Apache 1 and just switched to PHP5) when I had a similar problem was that unsetting 1 specific key (ie unset($_SESSION['key']);) was causing it not to save. As soon as I didn't unset that key any more it saved. I have never seen this again, except on that server on another site, but then it was a different variable. Neither were anything special.

Darryl Hein
A: 

Here is one common problem I haven't seen addressed in the other comments: is your host running a cache of some sort? If they are automatically caching results in some fashion you would get this sort of behavior.

gaoshan88
+5  A: 

Thanks for all the helpful info. It turns out that my host changed servers and started using a different session save path other than /var/php_sessions which didn't exist anymore. A solution would have been to declare ini_set(' session.save_path','SOME WRITABLE PATH'); in all my script files but that would have been a pain. I talked with the host and they explicitly set the session path to a real path that did exist. Hope this helps anyone having session path troubles.

Crackerjack
A: 

Just wanted to add a little note that this can also occur if you accidentally miss the session_start() statement on your pages.

A: 

"I know one solution I found (OSX with Apache 1 and just switched to PHP5) when I had a similar problem was that unsetting 1 specific key (ie unset($_SESSION['key']);) was causing it not to save. As soon as I didn't unset that key any more it saved. I have never seen this again, except on that server on another site, but then it was a different variable. Neither were anything special."

Thanks for this one Darryl. This helped me out. I was deleting a session variable, and for some reason it was keeping the session from committing. now i'm just setting it to null instead (which is fine for my app), and it works.

A: 

Check if you are using session_write_close(); anywhere, I was using this right after another session and then trying to write to the session again and it wasn't working.. so just comment that sh*t out

A: 

If you set a session in php5, then try to read it on a php4 page, it might not look in the correct place! Make the pages the same php version or set the session_path.

Harry
A: 

Check who the group and owner are of the folder where the script runs. If the group id or user id are wrong, for example, set to root, it will cause sessions to not be saved properly.

buzzy blogger
A: 

Had same problem - what happened to me is our server admin changed the session.cookie_secure boolean to On, which means that cookies will only be sent over a secure connection. Since the cookie was not being found, php was creating a new session every time, thus session variables were not being seen.

Shane N