Re: Session Array Disappears

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

 



add a ignore_user_abort(TRUE) first thing in your code.

Webmaster wrote:
Thanks for the reply.

Sorry, that was a typo in the email. I actually do have session_start(); at the beginning of the scripts. My bad.

Thanks,
R

Brady Mitchell wrote:
You're missing the session_start() call at the beginning of your code.
I'm surprised it works at all without that..

http://www.php.net/manual/en/ref.session.php
http://www.php.net/manual/en/function.session-start.php


Brady


-----Original Message-----
From: Webmaster [mailto:webmaster@xxxxxxxxxxx] Sent: Monday, April 24, 2006 1:49 PM
To: php-general@xxxxxxxxxxxxx
Subject:  Session Array Disappears

Hello,

The site I'm working on works like this...
Requires a login that uses sessions to remember username and email address. Upon being verified, the user is presented with a page that displays several questions regarding their background. Upon submitting the background page, a script checks to make sure all background questions were answered. If not, the page is redisplayed with a warning to answer all questions. If they are all present, a second page is displayed asking about a specific topic. Submitting the second page calls up the code provided below.

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). Also, session.gc_maxlifetime is set to 5400. We are using PHP 4.3.4.

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, hoping and/or praying that someone out there can look at this small script and let me know if I'm doing something wrong with the built in function array_pop, perhaps I don't understand sessions at all or perhaps it is a server issue. It's very confusing because other session variables (name and email from the login page) are not emptied, just $_SESSION['Q'].

Here's my code with some documentation:
<?php
/*
$_SESSION['startQA'] contains 11 elements and is generated by a previous page in the site. Once the visitor clicks the page two submit button, the above SESSION variable comes into play again.

This script takes that array of elements and does the following:
1. Assign session array to local array
2. Removes the last elemental value using array_pop
3. Removes the last elemental value using array_pop
4. Assign local variable the value of the a POST element
4a. Create a new session array and populates the first element equal to POST element
5. Runs through and populates the remaining 9 elements
5a. Total of 10 elements are now populated, 0 thru 9
6. Double checks the existence of each element
6a. if an element is missing, email me a warning and end program
*/

//Assign Session array to local variable
// Step 1
$thisQarray = $_SESSION['startQA'];
//Remove the last element of the original array
// Step 2
$area = array_pop($thisQarray);
//Remove last element of bgq array and assign to taking_test_at
// Step 3
$from_location = array_pop($thisQarray);
//Assign test version to variable
// Step 4
$testVersion = $_POST['version'];

//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];
}
//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
  END PROGRAM
}
?>

Thank you all very much,
R

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






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