Page 2 of 2

Posted: Sat Oct 25, 2003 3:49 pm
by kta
I'll definatly take your advice and get the debugger. But just for the hell of it:

Here are the last few lines from page 1. count($_SESSION) returns 6 as it should.

Code: Select all

<?php
     echo "<tr><td align='center' colspan='3'><a href='page2.php'>Page Two</a></td></tr>";
    echo "</table>";
    echo "<p>";
    echo "The size of the SESSIONS array is: ", count($_SESSION);
?>
</body>
</html>

Here are the first few lines from page 2. count($_SESSION) returns 0.

Code: Select all

<?php
   error_reporting(E_ALL);
   ini_set('display_errors', TRUE);
   session_start();
   header("Cache-control: private");
   echo "Size of SESSION array is: ", count($_SESSION);
?>

I see no problems with this code. Oh well. Thanks guys. Time for a break.

Posted: Sat Oct 25, 2003 6:02 pm
by kta
FIXED!

Apparently you can't use numbers as array identifiers only letters. For example:

$_SESSION['12'] = "cow"; This will work fine for the page you are on but can not be saved in the session data file. (this is what I was doing).

$_SESSION['twelve'] = "cow"; Works just fine.

Why is PHP written this way? It seems that numerics are commonly used in this manner in other languages.

In my script I'm writing lots of data into the $_SESSION array using for loops. $_SESSION[$i]="some data"; So this is going to cause some problems. I'll have to sit down and think about this. Thanks again for all your help guys.
- Evan

Posted: Sat Oct 25, 2003 10:03 pm
by volka
uh, right. And I couldn't find a bug report for that (which doesn't mean there is one ;) )
Maybe you want to post one?
Seems to affect only the top-level of $_SESSION

Code: Select all

<?php
session_start();
$i = count($_SESSION);
$_SESSION[] = date('D M j G:i:s T Y');
$n = count($_SESSION);
?>
<html>
	<head>
		<title>session test</title>
	</head>
	<body>
		<pre><?php echo($i); ?></pre>
		<pre><?php print_r($_SESSION); ?></pre>
		<pre><?php echo($n); ?></pre>
		<a href="<?php echo $_SERVER['PHP_SELF']; ?>">refresh</a>
	</body>
</html>
doesn't work
But

Code: Select all

<?php
session_start();
$i = count(@$_SESSION['whatever']);
$_SESSION['whatever'][] = date('D M j G:i:s T Y');
$n = count(@$_SESSION['whatever']);
?>
<html>
	<head>
		<title>session test</title>
	</head>
	<body>
		<pre><?php echo($i); ?></pre>
		<pre><?php print_r($_SESSION); ?></pre>
		<pre><?php echo($n); ?></pre>
		<a href="<?php echo $_SERVER['PHP_SELF']; ?>">refresh</a>
	</body>
</html>
does
(tested with PHP Version 4.3.3/win32 as module for Apache 2.0.47
and PHP Version 4.3.3/2.4.20-gentoo as module for Apache 2.0.47)