views:

400

answers:

4

I am trying to to solve a problem where I need to pass large arrays of data to another page, this is my scenario:

The user input his/her gmail login information inside a form, I then send this information to an ajax page where i authenticate and fetch all the contacts, if the login is invalid they can try again but if it authenticated I need to send them to the next page where I parse all the emails and check if they match any users on the site.

Method 1 (didn't work):

Store all the data inside a session, this only work if the array is small as there is a size limit for the sessions.

Method 2 (didn't work):

Add an hidden input with javascript and then submit the form (also with javascript). As it turns out you can't submit the form and return true (change page) unless the user triggers the event.

So how should I go on, should I just skip the ajax authentication and send them back to the previous page if it didn't work or is there some workaround to my problem?

+3  A: 

Why don't you store the data in a database, MySQL, or SQLite if MySQL is not available to you. In there, you would store a serialized version of your array linked to the users session id.

The MySQL table I'm thinking of:

id | session_id | data

http://php.net/manual/en/function.serialize.php on how to serialize your array.

x3ro
Thats a good idea. I think I will go with this solution, its faster then fetching the data once again from the webservice.
Dennis
Be careful with this approach. It works when you have a single database, but if you ever need to scale past that it's not going to work reliably. The lage between a master DB replicating out to it's slaves is often longer than the lag between page loads.
Alan Storm
A: 

If you are able to fetch the data again on the next page, you could do that instead of passing it between pages.

GSto
the call usually takes 3-6 seconds so I think x3ro's solution will be the optimal way of doing it.
Dennis
A: 

Since you are using jQuery you can submit the data directly or as a hidden element on the form without a user click. Assuming the second submission is via AJAX you can:

 $("#mydiv").load("secondpage.php", {email1: 'blah'}, function(){
   alert("Submitted everything nicely");
 });
Vincent Ramdhanie
that will disable the back button, is it possible to keep the back button and do it this way?
Dennis
To do it without AJAX you can use the '$("form").submit()' which does a full post. So you can add your hidden fields and submit the form from code.
Vincent Ramdhanie
That doesn't work, I cant trigger the submit function without a user click. I got it confirmed here:http://stackoverflow.com/questions/645555/should-jquerys-form-submit-not-trigger-onsubmit-within-the-form-tag
Dennis
What do you want to do in the onsubmit? As I understand it you can submit a form without user click, only it will not fire the onsubmit event...that should be easy to work around.
Vincent Ramdhanie
You can submit the form but all thats happens is that you run the submit function but It wont take you anywhere. The code just stop running after return true.
Dennis
A: 

Depending on your webserver, but session variables do not typically have a size restriction. Apache+PHP you could handle extremely large sizes, instead you should care about http://ca.php.net/manual/en/ini.core.php#ini.memory-limit. In addition, PHP.ini carries session.size variable that you could adjust. I am not sure how it did not work for you; you used $_SESSION, right?

Finally, to make a better persisting yet fast (faster than Database) volatile storage I would recommend using Danga's memcached. It is very stable, widely used and has wrappers for every possible language flavor.

Terry Felkrow