Jump to content

Recommended Posts

I am storing the contents of the POST array in a session:

 

$_SESSION['post_values'] = $_POST;

 

Then on another page, I am calling:

 

count($_SESSION['post_values'])

 

I would expect count to return the number of fields in the original POST request, which is 22, but instead it returns something like 92,000+. Ideas why?

Link to comment
https://forums.phpfreaks.com/topic/130008-storing-post-values-in-a-session/
Share on other sites

So the first time I view the $_SESSION['post_values'] array it only has the form values, but when I refresh it ballons in size to over 90,000 values.

 

Here is the output of print_r($_SESSION['post_values']

 


Array ( [customer_name] => Test Customer [customer_contact_first_name] => John [customer_contact_last_name] => Doe 
[customer_address] => my address [customer_city] => my city[customer_state] => CA [customer_zip] => 90210 [customer_contact_phone] => 222-222-2222 
[customer_contact_mobile] => [customer_contact_fax] => [shipping_contact_first_name] => John[shipping_contact_last_name] => Doe 
[shipping_address] => my address [shipping_city] => my city [shipping_state] => CA [shipping_zip] => 90210 [shipping_contact_phone] => 222-222-2222 
[shipping_contact_mobile] => [shipping_contact_fax] => [account_manager] => Jane Doe [customer_timezone] => Pacific Time [po_number] => 
[shipping_method] => Ground [terms] => 100% Down [onetime_quantity_1] => [onetime_description_1] => [onetime_unit_price_1] => [onetime_amount_1] => $0.00 [onetime_quantity_2] => [onetime_description_2] => [onetime_unit_price_2] => 
[onetime_amount_2] => $0.00 [onetime_quantity_3] => [onetime_description_3] => [onetime_unit_price_3] => [onetime_amount_3] => $0.00 
[onetime_quantity_4] => [onetime_description_4] => [onetime_unit_price_4] => [onetime_amount_4] => $0.00 [onetime_quantity_5] => [onetime_description_5] => [onetime_unit_price_5] => [onetime_amount_5] => $0.00 [monthly_quantity_1] => [monthly_description_1] => [monthly_term_1] => [monthly_unit_price_1] => [monthly_amount_1] => $0.00 [monthly_quantity_2] => [monthly_description_2] => [monthly_term_2] => [monthly_unit_price_2] => [monthly_amount_2] => $0.00 [monthly_quantity_3] => [monthly_description_3] => [monthly_term_3] => [monthly_unit_price_3] => [monthly_amount_3] => $0.00 [total_monthly] => $0.00 [subtotal] => $0.00 [sales_tax] => $0.00 [shipping_and_handling] => $0.00 [total_due] => $0.00 [customer_username] => Tester [customer_password] => Tester [general_contact_first_name] => Test [installation_contact_first_name] => Test [billing_contact_first_name] => Test [general_contact_last_name] => Test [installation_contact_last_name] => Test [billing_contact_last_name] => Test [general_contact_phone] => Test [installation_contact_phone] => Test [billing_contact_phone] => Test [general_contact_email] => [email protected] [installation_contact_email] => [email protected] [billing_contact_email] => [email protected] [hardware_payment_method] => check [monthly_fee_payment_method] => credit_card [comments] => [action] => Continue --> [0] =>   [1] =>   [2] =>   [3] =>   [4] =>   [5] =>   [6] =>   [7] =>   [8] =>   [9] =>   [10] =>   [11] =>   [12] =>   [13] =>   [14] =>   [15] =>   [16] =>   [17] =>   [18] =>   [19] =>   [20] =>   [21] =>   [22] =>   [23] =>   [24] =>   [25] =>   [26] =>   [27] =>   [28] =>   [29] =>   [30] =>   [31] =>   [32] =>   [33] =>   [34] =>   [35] =>   [36] =>   [37] =>   [38] =>   [39] =>   [40] =>   [41] =>   [42] =>   [43] =>   [44] =>   [45] =>   [46] =>   [47] =>   [48] =>   [49] =>   [50] =>   [51] =>   [52] =>   [53] =>   [54] =>   [55] =>   [56] =>   [57] =>   [58] =>   [59] =>   [60] =>   [61] =>   [62] =>   [63] =>   [64] =>   [65] =>   [66] =>   [67] =>   [68] =>   [69] =>   [70] =>   [71] => ..... ETC UP TO [93963] => )

Let me explain the problem. I am trying to run the following code below, but because the $_SESSION['post_values'] array is so large > 90,000, this code locks up and does'nt finish.

 

for($i = 0; $i < count($_SESSION['post_values']); $i++) {
	if(empty($_SESSION['post_values'][$i])) {
		$_SESSION['post_values'][$i] = ' ';		
	}
}

 

 

Ok here is the code:

 

<< form page>>

 

Top of the page

 

      session_start();

 

....

 

When the form is submited runs this block:

 

$_SESSION['post_values'] = $_POST;
			echo '<p align="center" class="success">Success!</p>';
			echo '<script type="text/javascript">document.location = \'order_form.php\';</script>';
			die();

...

 

<< order_form.php >>

 

session_start();

if(!isset($_SESSION['post_values'])) {
	die("<h1>Woops. There is no session set.</h1>");
}

print_r($_SESSION['post_values']);

//Check All Fields, If Empty Then Insert ' '
for($i = 0; $i < count($_SESSION['post_values']); $i++) {
	if(empty($_SESSION['post_values'][$i])) {
		$_SESSION['post_values'][$i] = ' ';		
	}
}

Argh, Its your for loop that is the cause.

 

Your post_values sessions variable is an associative array, however your using a number to access each item in the array. This is not possible. Instead your should use a foreach loop

foreach($_SESSION['post_values'] as $field_name => $file_value)
{
    if(empty($field_value))
       $_SESSION['post_values'][$field_name] = ' '; 
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.