User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion

Reply
Thread Tools Display Modes
Unread 19 Nov 2002, 11:45   #1
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
PHP Sessions problem

Anybody have any idea why $_SESSION vars may mysteriously lose their values?

I set (for ex): $_SESSION[id] = 1; on page one of a set of forms. At the top of each page (the first thing) is session_start ();.

I do a print_r ($_SESSION); at the top of each page, and by about the 4th page, id has lost its value. Any ideas why this could be?

Cheers,

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 19 Nov 2002, 15:35   #2
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Quote:
Caution
If you are using $_SESSION and disable register_globals, do not use session_register(), session_is_registered() and session_unregister(), if your scripts shall work in PHP 4.2 and earlier. You can use these functions in 4.3 and later.

If you enable register_globals, session_unregister() should be used since session variables are registered as global variables when session data is deserialized. Disabling register_globals is recommended for both security and performance reasons.
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 19 Nov 2002, 18:51   #3
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
I know that, but thanks

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 19 Nov 2002, 19:21   #4
mbushell
Registered User
 
mbushell's Avatar
 
Join Date: Jul 2000
Location: :noitacoL
Posts: 1,200
mbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus wouldmbushell spreads love and joy to the forum in the same way Jesus would
Quote:
With $_SESSION or $HTTP_SESSION_VARS, there is no need to use session_register()/session_unregister()/session_is_registered() functions.
Edit: I've not solved your problem have I :/
mbushell is offline   Reply With Quote
Unread 20 Nov 2002, 12:57   #5
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Quote:
Originally posted by mbushell


Edit: I've not solved your problem have I :/
Actually, no. But I was too polite to say anything

M.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"
Mong is offline   Reply With Quote
Unread 23 Nov 2002, 01:07   #6
Breed
Albatross!
 
Join Date: Mar 2000
Location: Oslo
Posts: 14
Breed is an unknown quantity at this point
ohhh

You have a well known (ok relativly well known) bug there...

The #15983 bug it looks like.

Afaik this bug was closed from debug in version 4.2.3 so if you are using any other version you should consider an upgrade.

The contents of the bug:

Here is part of what is going wrong. PHP starts out with each session
variable appearing as a global and also in $_SESSION. Initially these
are linked by reference (not clear how) and contain the same data.
This linkage appears to get broken so the contents $GLOBALS['S']
and $_SESSION['S'] are not the same. $GLOBALS contains the latest data,
$_SESSION contains the data as of the start of the page. Consequently
changes to the $_SESSION variable are not being saved between pages.

My workaround is to use the following at the end of each page for $S:

if ( !($_SESSION['S'] === $S) )
$_SESSION['S'] = $S;

This updates the contents of the $_SESSION variable if it is not longer
the same as the global.

Based on a comment from one of the developers, the problem may relate to
having a global declaration for a session variable that appears outside
a function scope.

-----------------------

If you don't want to upgrade the PHP version you can fix it yourself:

The following patch seems to workaround the problem for

--- ext/session/mod_files.c.orig Tue Apr 23 20:10:49 2002
+++ ext/session/mod_files.c Thu Aug 22 11:41:05 2002
@@ -255,12 +255,16 @@
data->st_size = *vallen = sbuf.st_size;
*val = emalloc(sbuf.st_size);

+/*
#ifdef HAVE_PREAD
n = pread(data->fd, *val, sbuf.st_size, 0);
#else
+*/
lseek(data->fd, 0, SEEK_SET);
n = read(data->fd, *val, sbuf.st_size);
+/*
#endif
+*/
if (n != sbuf.st_size) {
efree(*val);
return FAILURE;

I.e., use of the read instead of pread seems to fix
the problem.
I wonder if this is a PHP bug (maybe endianess?)
or a glibc bug.



Chriso
__________________
.........................
Any kiddie in school can love like a fool,
But Hating, my boy, is an Art.
-- Ogden Nash
Breed is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Forum Jump


All times are GMT +1. The time now is 04:11.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018