Welcome Guest, Not a member yet? Register   Sign In
PHP Session values are getting destroyed...
#1

[eluser]M52 Studios[/eluser]
Hey everyone! Just want to say that I have been using CodeIgniter for some time now, and it is absolutely amazing - Thank you for all your hard work!

My question is in regards to native PHP Sessions - so the ones where you would use $_SESSION - not CodeIgniter's session class.

I am trying to get data from multiple pages and then insert them into the database once all the data has been collected. However, I am loosing values when going from page to page, but the keys in the $_SESSION array remain. Any ideas?

Thanks in advance!
#2

[eluser]John_Betong[/eluser]
Try logging the results and check the login file:

Code:
// set your Error Logging Threshold
// ./config/config.php
$config['log_threshold'] = '4';

// start logging
$old_stuff = $_SESSION['collected_values'];
$new_stuff = $old_stuff .$value_to_save;

log_message('error', __LINE__ .': ' .$new_stuff);

$_SESSION['collected_values'] = $new_stuff;
 
 
 
#3

[eluser]M52 Studios[/eluser]
Thanks, John! I've changed the 'log_threshold' to 4, not too sure where you are going with the rest of the script, though.

Also, just wanted to clarify. My Session Array looks like this on the second page:
SESSION: Array
(
[legal_name] => legal name
[display_name] => public name
[live_support] => No
[phone] => 123456789
[website] => www.www.com
[insured] => 6
[start_year] => 1986
[association] => No
[short_description] => short company description
)

and like so, on third...
SESSION: Array
(
[legal_name] =>
[display_name] =>
[live_support] =>
[phone] =>
[website] =>
[insured] =>
[start_year] =>
[association] =>
[short_description] =>
[permit_number] => 123456789
[permit_issuer] => name
[contact_first] => firstName
[contact_last] => lastName
[contact_phone] => 123456789
[address_1] => address 1
[address_2] => address 2
[zip_code] => 12345
[city] =>
[state] =>
[service_city] => service city
[service_state] => service state
)
#4

[eluser]John_Betong[/eluser]
Hi,

I am not sure from your post what session data variable you are losing.

It would also be useful to show the code which stores the session variable.

if you are losing the 'legal_name' then use this code and it will show you where it is being lost.

Code:
if ( isset($_SESSION['legal_name']) )
{
  log_message('error', __FILE__ . ': ' .__LINE__ .': ' .$_SESSION['legal_name']);
}else{
  log_message('error', __FILE__ . ': ' .__LINE__ .': $legal_name is NOT SET']);
}
 
 
 
#5

[eluser]M52 Studios[/eluser]
Yes, I am losing [legal_name], [display_name], [live_support], [phone], [website], [insured], [start_year], [association], [short_description].

and, then, when I move to the next page of the form, I lose the [permit_number] ... [service_state]

Again, the above is a copy of "print_r($_SESSION);"

To store the variables I am using the following syntax for all of them in separate functions. So for example the first one would be:

Code:
function process_part1()
{
   $_SESSION['legal_name'] = (isset($_POST['legal_name'])) ? $_POST['legal_name'] : NULL;
   ...
}
#6

[eluser]John_Betong[/eluser]
If you are losing so many variables then I would concentrate on just 'legal_name'. Once that manages to not get lost then the remaining variables should follow suit.

Try this:
Code:
//
session_start();
log_message('error', __FILE__ . ': ' .__LINE__ .': ' .$_SESSION['legal_name']);


// and here

function process_part1()
{
  if(! isset($_POST['legal_name']) || ('' = $_POST['legal_name'])
  {
   log_message('error', __METHOD__  .': EMPTY $_POST[legal_name]']);
   die; // no point in continuing
  }

  $_SESSION['legal_name'] = (isset($_POST['legal_name'])) ? $_POST['legal_name'] : NULL;

   ...
}
 
 
 
#7

[eluser]M52 Studios[/eluser]
Something strange is going on with the $_SESSION, I'm going to have to take another look into it later. For now I think that I will just store the temporary data into a database and pull from it using a final insertion into the actual table.

Thanks for your help! I'm going to have to use native PHP sooner or later, so I will need to sort this out. I'll let you know if I find anything interesting.




Theme © iAndrew 2016 - Forum software by © MyBB