CodeIgniter Forums
session data loss in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: session data loss in codeigniter (/thread-64013.html)



session data loss in codeigniter - neenz - 01-03-2016

So here is the problem i am facing. i have 3 views 1 controller . data has to pass from first view to second and then in third after which i insert it into database.. i fill the data in first form(view) post it. controller checks if i have logged in n stores data into a session or if its a click on back button on 2nd view then it should fetch data from session which is set (example $this->session->set_userdata('formarr', $formarr); i.e post from first form).
Now i fill data in 2nd form (view), post it. controller checks if i have logged in n stores data into a session or if its a click on back button on 3rd view then it should fetch data from session which is set in another 2nd array (example $this->session->set_userdata('vehicle_details', $veharr);i.e post from second form).
both these variables are now taken and 3rd view is loaded lets say confirmation view.which wen submitted it inserts into database.
now my problem arises when i click on back button its an href (eg :/home/newvehicle/confirm ) it shows both arrays in session .. but wen i submit.. i loose first array(formarr turns with keys but no values).. i guess its due to no posting of data.. but i dont know what would be a solution for the same.
Please if anyone can guide me it would make my day.



RE: session data loss in codeigniter - neenz - 01-04-2016

Is there really no solution to this?


RE: session data loss in codeigniter - PaulD - 01-05-2016

There is a solution to every problem.

It is hard to say where your problem lays but it is probably the use of the back button. The back button can be problematic if your page has not been designed with this in mind. I have, in the past, had similar issues, but now I have learned to keep the back button in mind.

For example, how are you identifying which stage of the 3-stage process your user is in? Do you have a step in the link, eg:www.mydomain.com/controller/method/step-1 or are you using different methods, but assuming in your method (wrongly) that data is available? Are you using an identifier to check for fresh information or resent information (such as a hidden form field that should be incrementing).

The usual solution for me, if I have understood you correctly, is to use the same method in the stages and to identify the stage we are on from a hidden field or url variable. The intermediate data from the steps can be stored in a table or in a cookie (whichever makes more sense in you case). Your method should be written so that the back button and subsequent re-submission of a stage does not presume the existence of any info. So if, for example, you submit stage 2 data, but stage 1 data is missing, you need to represent the stage 1 form with a user message if required.

For me, with e-commerce sites that confirm an order before submission to payment processor, the data from the order is already written to a table, and confirm just re-reads it all. If they have used the back button to get back to that page and try resubmitting, the row has been identified as already submitted, and so I can deal with that user error appropriately.

The back button may, or may not, reload the page from the server. It might just reload it from local cache. That is why the back button is a pain.

The best way to do this, IMHO, is with Ajax. That way the back button can not interfere with the page process.

I hope something here helps. If not, try to isolate the issue by creating a test page and simplifying the code until the core of the issue can be easily represented. Then post the code here and I am sure someone will be able to spot the problem for you.

Best wishes,

Paul.