PDA

Click to See Complete Forum and Search --> : [RESOLVED] Misbehaving Sessions


andrewb
Mar 9th, 2007, 10:05 PM
Hi Folks,

I am tearing my hair out trying to get sessions to work, I've tried the simple example code below to test whether sessions were working as they're meant to.

<?php
session_start();
$count = $_SESSION["counter"] + 1;
$_SESSION["counter"] = $count;
echo $_SESSION["counter"]." / ".session_id();
?>
Everytime I run this page, the counter does not increment and the session ID changes (and it is writing session files to the temp folder, with every pageview). Any ideas? My session variables in PHP.INI are as follows (I've not included the commented out variables):

session.save_handler = files
session.save_path = "C:\Temp"
session.use_cookies = 0
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = \
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5

kows
Mar 9th, 2007, 11:48 PM
this is the default php.ini-recommended session block for php 4.4.2. I tried that example code on my own server with these settings and it worked fine.
[Session]
session.save_handler = files
;session.save_path = /tmp
session.use_cookies = 1
; session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
;session.entropy_length = 16
;session.entropy_file = /dev/urandom
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
next, I used your php.ini settings and it did what you were describing. it was writing to the directory fine, as well. I enabled cookies for it and it worked fine -- although I'm not sure if you want to do that or not. I really know absolutely nothing about sessions, so you could just have to do something else to get sessions working without cookies? I would probably wait for someone else to post some knowledge for you, if you aren't interested in using cookies.

andrewb
Mar 9th, 2007, 11:55 PM
Thanks kows, I had tried with and without cookies enabled, but it must have had something to do with the files, I'm really not sure. Resolved for now :)