|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-03-10 09:14 UTC] sl at scrooge dot dk
The session variables are lost between pages. For example: session1.php: <? session_start(); $test = "Hello world"; session_register(test); ?> session2.php: <? session_start(); echo $test; ?> The output on page two is the empty string. A look at the sess_* in /tmp show that it contain the variable and the value after a request on session1.php. After a request on session2.php the file is empty. This error shows up in php 4.1.1 and 4.1.2. In version 4.0.6 everything works as it is suppose to. uname --all: Linux indy01 2.4.16 #1 Sun Dec 16 16:38:44 CET 2001 mips unknown gcc --version: 2.95.4 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
Reopen if this script does not work for you with PHP 4.2.0: <?php session_start(); if(!isset($_SESSION['test'])) { $_SESSION['test'] = 0; } echo $_SESSION['test']++; ?> It works fine here..(reloading the page increases the count) --JaniI'm working with win version 4.1.2, and while the very first example's code worked find for me (printed 'Hello world' as expected), the test script from sniper@php.net did not. From my testing, it appears as though using $_SESSION just doesn't register a value with the session, although it maintains any changes to a variable once it has been registered with the session. If instead of, <?php if(!isset($_SESSION['test'])) { $_SESSION['test'] = 0; } echo $_SESSION['test']++; ?> you use, <?php if(!isset($_SESSION['test'])) { $test = 0; session_register('test'); } echo $_SESSION['test']++; ?> the script will increment the variable just fine. But because $_SESSION['test'] = 0; doesn't set/register the variable the first time, each time you refresh you will find yourself stuck in the if statement, and the value still stuck at 0. -- foosThe following patch seems to workaround the problem for me, on Debian Woody PPC: --- 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.It seems that also on WinXP, when I do redirects between pages, I experience the same problem, using header("Location: URL");.Look at these examples, refresh the same file: Example 1 works fine: --------- <?php GLOBAL $HTTP_SESSION_VARS; session_start(); ;session_register('AVAR'); $HTTP_SESSION_VARS['AVAR'] += 1; print "<p>variable={$HTTP_SESSION_VARS['AVAR']}</p>"; ?> Example 2 doesn't work correctly: --------- prints always "count=1" and thats stored in the session file: <?php session_start(); GLOBAL $count; session_register("count"); $count++; print "<p>count=$count</p>"; $count=10; ?> For scalars Ex. 1 would be ok, but how to deal with objects? I'm using PHP 4.2.2 (same was with 4.2.1) on Windows2000.If you want us to avoid using certain features of your platform, then you need to provide specific testcases. We will use these testcases to determine whether pread/pwrite work on a platform. Currently, we use this for pread (after echo test > conftest_in): #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> main() { char buf[3]; return !(pread(open("conftest_in", O_RDONLY), buf, 2, 0) == 2); And this for pwrite: #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> main() { return !(pwrite(open("conftest_in", O_WRONLY|O_CREAT, 0600), "hi", 2, 0) == 2);Cerecita.com SOLUTION One thing easy thing. I used POST, I used GET, and variables were lost. I thought, why phpMyAdmin is working? I did check their code and found at the beginning of the index.php page the use of: require ('yourpath/libraries/grab_globals.lib.php'); I dont know what it does, but every thing is working fine now in all servers, with simple code, not workarounds. Thanks oscar@cerecita.com