|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-05-09 11:34 UTC] mats at cdmedia dot nu
I'm having problems using $_SESSION, it throws away some of my values between page loads. The following code triggers the problem.
<?
session_start();
print "<PRE>";
print "Current values:\n";
print '"foo"=' . $_SESSION["foo"] . "\n";
print '4=' . $_SESSION[4]."\n";
print '"a"=' . $_SESSION["a"]."\n";
$_SESSION["foo"] = "bar";
$_SESSION[4] = "four";
$_SESSION["a"] = "b";
if(!isset($_SESSION["counter"]))
$_SESSION["counter"] = 1;
else
$_SESSION["counter"]++;
print "Count = ".$_SESSION["counter"]."\n";
print "</PRE>";
?>
The first run, it prints this:
Current values:
"foo"=
4=
"a"=
Count = 1
Which is what is expected, since the values haven't been set yet, except for the counter.
Now the second run, this is where the problem show up:
Current values:
"foo"=bar
4=
"a"=
Count = 1
This seems to be wrong! The first value has been set, but none of the others. The counter should have been incremented also. The expected result of the second run would be
Current values:
"foo"=bar
4=four
"a"=b
Count = 2
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 19:00:01 2025 UTC |
what if you try : <? session_start(); session_register("foo"); session_register(4); session_register("a"); session_register("counter"); print "<PRE>"; print "Current values:\n"; print '"foo"=' . $_SESSION["foo"] . "\n"; print '4=' . $_SESSION[4]."\n"; print '"a"=' . $_SESSION["a"]."\n"; $_SESSION["foo"] = "bar"; $_SESSION[4] = "four"; $_SESSION["a"] = "b"; if(!isset($_SESSION["counter"])) $_SESSION["counter"] = 1; else $_SESSION["counter"]++; print "Count = ".$_SESSION["counter"]."\n"; print "</PRE>"; ?> $_SESSION["foo"] and $_SESSION["counter"] should be working $_SESSION[4] doesn't (I guess its because of the numerical key) and $_SESSION["a"] neither (but works if "a" is changed to "ab"). /LeblancI struggled with the $_SESSION problem for almost a week. When I read this report, that is when reality hit me. In the comment written by "sniper@php.net" saying that I'm not suppose to use the numberic value. I'm using PHP 4.2.1 and AIX 4.3.3. Here's the example that work which should not have work at all. See the "//This one work!! (Numberic Value)". Why do I have to spend almost a week struggling over it? I read many documentation about $_SESSION vs. session_register() with the register_global turned off, but they say nothing about the numeric value that aren't allowed to be used? Thanks, FletchSOD --clip-- //-------Page 1--------- define(CUSTOMER_ID,0); define(CUSTOMER_NAME,1); define(STREET,4); define(CITY,5); define(STATE,6); define(ZIP_CODE,7); $salt = strtoupper(md5(uniqid(rand()))); session_id($salt); session_start(); //$result is from odbc_exec odbc_fetch_into($result,$_SESSION,1); //Example #1 print_r($_SESSION); //This one work!! (Numeric Value) //Example #2 echo $_SESSION[0]; //This one work also! (Numberic Value) header("Location: https://www.whatever.com/page2.php"); //-------Page 2--------- session_start(); print_r($_SESSION); //This one does not work! --clip--I've been having a similar problem for over a week. Tried everything I could think of. Script looked like this: <? GLOBAL $HTTP_SESSION_VARS; session_start(); $AVAR += 1; session_register('AVAR'); print "<p>variable={$HTTP_SESSION_VARS['AVAR']}</p>"; ?> Seemed everyone else could get it to work except for a friend and I. I'm using IE 6.0.28, he's using Netscape 4.04. I was able to correct the problem by doing the following while running IE6.0.28: a) Select Tools/Internet Options b) Select Privacy Tab c) Click on Advanced button d) Check Override Automatic Cookie Handling e) Check Always allow session cookies After doing this - everything worked fine - even the test scripts above (except for the variable 4). I then went back and unchecked the Override Automatic Cookie Handling - assuming that this would return me back to a state where AVAR would not increment. Much to my chagrin, it continued to work. This leads me to believe that there's a registry setting somewhere that controls this behavior. Now, to find out what it is and how to check for it on a user's machine from within PHP.....