Re: Session Array Disappears

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Thank you for the reply.

Richard Lynch wrote:

On Mon, April 24, 2006 2:48 pm, Webmaster wrote:
In reading the www.php.net/manual/en/ref.session.php page, I'd like to
point out we do not use cookies.  The session id is propagated in the
URL (although it's not visible in the URL bar).

Something is very odd here...

Unless the session data is being passed as an INPUT TYPE="hidden" in a
FORM, it has to be in the URL to work.

It should be visible in the URL bar if it's in the URL.

Though, obviously, the thing works, so it's not your "problem" here...
It's just something you should investigate for your own learning
experience, rather than to solve your problem today.

I apologize, I should have been more clear, and I should have thought a little more before describing the situation. Users navigate from page to page by use of a <form method="POST"> submit button. They do not use <a href> links to go from page to page.

Not very often, but once in a while, I'll get an email warning me that
a
submission was denied because $_SESSION['Q'] is empty.  I'm wondering,
//Start building the final Session Array
// Step 4a
$_SESSION['Q'] = array($testVersion);

//Populate rest of Session Array
// Step 5
for ($newBGQCounter=0; $newBGQCounter<count($thisQarray);
$newBGQCounter++)
{
 $_SESSION['Q'][$newBGQCounter+1] = $thisQarray[$newBGQCounter];
}
This is the source of your troubles.

Step 4a is pointless.

Try this in a small test file:
<?php
$anything['Q'] = 'x';
$anything['Q'][1] = 'y;
print_r($anything);
?>

Per your suggestions, here's a couple of tests I ran and the results I received:

<?php
session_start();
$testVariable = 'a';
$_SESSION['test'] = array($testVariable);
$_SESSION['test'][1] = 'b';
print_r($_SESSION['test']);
?>
Results:
Array ( [0] => a [1] => b )
(desired result, basically what I'm using now)

<?php
session_start();
$testVariable = 'a';
$_SESSION['test'] = $testVariable;
$_SESSION['test'][1] = 'b';
print_r($_SESSION['test']);
?>
Results:
ab
(treats it like a string instead of an array, undesired result)

<?php
session_start();
$testVariable = 'a';
$_SESSION['test'][0] = array($testVariable);
$_SESSION['test'][1] = 'b';
print_r($_SESSION['test']);
?>
Results:
Array ( [0] => Array ( [0] => a ) [1] => b )
(creates multi-dimensional array, undesired result)

<?php
session_start();
$testVariable = '1';
$_SESSION['test'][0] = $testVariable;
$_SESSION['test'][1] = '2';
print_r($_SESSION['test']);
?>
Results:
Array ( [0] => 1 [1] => 2 )
(desired result)

According to these tests, I could use the first example or the last example to achieve the desired results.

//test for existense of session array elements
if ( ($_SESSION['Q'][0] == "") OR ($_SESSION['Q'][1] == "") OR
($_SESSION['Q'][2] == "") OR ($_SESSION['Q'][3] == "") OR
($_SESSION['Q'][4] == "") OR ($_SESSION['Q'][5] == "") OR
($_SESSION['Q'][6] == "") OR ($_SESSION['Q'][7] == "") OR
($_SESSION['Q'][8] == "") OR ($_SESSION['Q'][9] == "") )
{
 SEND ME AN ERROR EMAIL

It might be a Good Idea for this error email to dump out ALL of
$_SESSION['Q'] as well as all the variables you think are involved in
your problem.

You would then be able to backtrack and debug this issue in the future.
I agree. I actually realized this yesterday after I sent my email to the list. I'm in the process of adjusting the code to include variables in the email. Thank you for the suggestion(s). They are greatly appreciated.

At this point, here's my "logical" thinking....
1. Occassionaly, the background information session array is missing one or more elements thus an email is generated and the script ends immediately. 2. In the email portion of the script, which is after the array element check, I call other session variables (username, email address) and they are present. 3. Given the above information, I'm inclined to believe that it's got something to do with just the background information session array. 3a. Perhaps array_pop is the problem, it works differently then I thought?.?. 3b. Perhaps the way I construct the session array corrupts it (using a "for" loop)?.?.
4. Perhaps session variables are not really intended to contain arrays?.?.
5. I'm not sure if any user interactions (web accelerator, ISP issues or Forward/Back/Reload browser buttons) would cause such an issue?.?.

Looking at the above list, I can only deal with item 3. I could change my session array code to populate it like this:

$_SESSION['Q'][0] = $testVersion;
$_SESSION['Q'][1] = $thisQarray[0];
$_SESSION['Q'][2] = $thisQarray[1];
$_SESSION['Q'][3] = $thisQarray[2];
$_SESSION['Q'][4] = $thisQarray[3];
$_SESSION['Q'][5] = $thisQarray[4];
$_SESSION['Q'][6] = $thisQarray[5];
$_SESSION['Q'][7] = $thisQarray[6];
$_SESSION['Q'][8] = $thisQarray[7];
$_SESSION['Q'][9] = $thisQarray[8];

I'm really at a loss and have no idea what else to try other then the above code.

Thanks,
R

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux