Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error messages stored in SESSION

Tags:

php

session

Is it a good practice to store error messages in SESSION? For example after a redirect. Passing in through url isnt a solution for me... I am wondering if it is a good solution... because..

Would a concurent submit of user cause problem? (A long time-taking post, while ajax content is obtained from another tab) that may mess up the session! Or that is impossible to happen?

If user makes a request and it fails for some reason to display the page then the message may be shown at an irrelevant page!

So? Any alternatives??
For example when using POST/redirected/get pattern

like image 637
GorillaApe Avatar asked Nov 29 '10 10:11

GorillaApe


3 Answers

When storing error messages in the session, you must take care, that two request dont overwrite the other ones message, before it is displayed. And you must take care, that a page, that should display a message, only displays its own message.

You should show errors, when they occur and not redirect before. Also there is no reason to redirect in such a situation.

like image 130
KingCrunch Avatar answered Oct 09 '22 22:10

KingCrunch


Is it a good practice to store error messages in SESSION? For example after a redirect.

Not in general. Session data should be data that matters for a significant period, errors are generally a result of a single request and the details don't need to persist.

Storing that sort of data in a session is just an invitation to race conditions.

like image 5
Quentin Avatar answered Oct 09 '22 23:10

Quentin


why dont you assign them an specific id like error_id=2 and send them through url? or is this also not possible in you case? you could also send an error id through session...

like image 3
Florin Andrei Avatar answered Oct 09 '22 23:10

Florin Andrei