|
Posted by Webmaster on 05/12/05 02:46
Hello,
I have an application that occasionally drops a session array element value.
Data from the form...
$_POST['firstName'];
$_POST['lastName'];
$_POST['phone'];
$_POST['email'];
$_POST['cell'];
When the form is submitted, the POST variables are checked to make sure
they each contain a value. If not, the form is redisplayed and the user
is alerted to the missing data. The next step in the process places the
data into an array and then assigns the array to a session variable...
$userData = array ($_POST['firstName'], $_POST['lastName'],
$_POST['phone'], $_POST['email'], $_POST['cell']);
$_SESSION['userData'] = $userData;
The user then visits some other pages and fills out some more data. At
one point, it is necessary to remove the last two elements from the
session array. This is achieved by using array_pop...
$cellPhone = array_pop($_SESSION['userData']);
$emailAddress = array_pop($_SESSION['userData']);
And then it is necessary to add a different variable to the beginning of
the session array...
$userCleared = "ok";
array_unshift($_SESSION['userData'], $userCleared);
Finally, the data is checked again to make sure values exist. At this
point, occasionally, one of the element values of the session array is
missing. It's never the same one. It seems that, at random, one of the
elemental values just goes away. The others are still there. If an
element is missing, I receive an email alerting me to this fact. I can
think of other ways to handle all of this data, but my question is
this...would the current code cause elements to loose their value?
Would using a session array AND the array_pop or array_unshift cause
this to happen? Has anyone else experienced this sort of occasional
anomaly?
Thanks,
Rog
Navigation:
[Reply to this message]
|