Re: Session Array Disappears

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

 



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.

> 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);
?>

You will not see an 'x' in the output anywhere.

$anything cannot be a 1-dimensional array and a 2-dimensional array at
the same time.

You'll need to store the data from Step 4a in some special 2-D place
within $_SESSION['Q']

It looks from your code that perhaps $_SESSION['Q'][0] would be an
ideal candidate, as you are using $newBGQcounter+1 as an index, and
$newBGQcounter starts at 0 and goes to the size of some other array.

So you are using 1, 2, 3, 4, ... for the $thisQarray, and you can cram
the $testVersion into index 0.

On the other hand, it would probably be MUCH better to not try to cram
$testVersion and $thisQarray into the same data structure.

Maybe what you SHOULD be doing is more like:
$_SESSION['testVersion'] = $testVersion;
$_SESSION['thisQarray'] = $thisQarray;

Then you won't be confusing yourself with what's what in the SESSION
data because the names will match up.

There is no need to iterate through an array just to copy it into
$_SESSION -- you'll have the indices running from 0 instead of from 1,
but you really should just get used to that, and if you ever need to
print the index out for a human, only change the numbering on output,
not on your internal data structures.

> //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.

>   END PROGRAM
> }
> ?>

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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