Scenario: site.com has a search bar with all sorts of input fields where once all those are filled will redirect the user to site.com/results which will show the user’s search results based on the filters they set up on the previous page. Now, site.com/results/1 will show each individual search result. However, whenever a user hits ‘back’ from site.com/results/1 all of the previous filters that were set up by the user initially are erased. My boss doesn’t want that. Also, in the future possibly my boss would want to implement sending emails for search results that had been ‘abandoned’ same as that with an abandoned shopping cart.
I am wondering if localStorage + AJAX would be perfect for this? Maybe from site.com once the user fills up the input fields have those values stored in the localStorage and use those values in the filters of site.com/results and also insert them to my AJAX calls when user changes the filters in site.com/results to dynamically change the results on that page. And in the future, have the values in localStorage be sent over to the user by email.
Or would I better off using php COOKIES or SESSION instead? (site uses PHP on the back end)
How come? Can you give me a sample scenario where sessionStorage is more useful in my case? Just so I can understand it more clearly. Thanks.
Edit: I’ve given it some thought but since sessionStorage expires once the browser is closed, wouldn’t that pose a problem for me when sending out emails for abandoned search results?
This sounds like a good use case. I agree with using sessionStorage. The difference is that sessionStorage isn’t retained after the session has ended, where as localStorage is retained until it’s cleared. It doesn’t sound like you need to retain these values after the site is closed.
You should try to avoid using sever side sessions wherever possible.
Edit: I’ve given it some thought but since sessionStorage expires once the browser is closed, wouldn’t that pose a problem for me when sending out emails for abandoned search results?
Both sessionStorage and localStorage exist on the client’s browser. This doesn’t effect you sending emails. Either way, you need to send this back to the server to track abandoned search results. The only way you’ll be able to do it is to send it constantly back to the server and cross check that with their searches.
Dangerous statement without definition of ‘wherever possible’.
It’s POSSIBLE to avoid using a server side session when logging into a website, and storing locally and transmitting the password over and over for calls to server pages. But it’s hardly recommended.
Better phrase would probably be ‘wherever sensible’, but again probably needs a definition (where security isn’t a concern, etc)
Ok so now I’m totally confused. How am I possibly going to send a user an email regarding their abandoned page and store the same inputs with sessionStorage when they’ve already closed out their browser? Hence, the ‘abandoned’ part. Also, could you explain why I should avoid server side sessions?
You’ll find that localStorage cannot help with the sending of emails either because that’s only available on the local client’s side.
You’ll need to store the search terms in a server database and clear them when a successful search as been performed.
Then once per hour you can check for any searches that are more than an hour old, and email about them, setting a flag against those searches that an email has been sent.
This is a bold statement. I absolutely recommend using JWTs wherever possible. Probably out of scope here, but generally for new projects.
In either case, as little information that you can store in the session the better. It’s a good habit to develop like server-side session storage doesn’t exist because relying on it too much doesn’t scale well. Which was more along the lines of what I meant in my last reply here. You’re probably talking about authentication details, and JWTs are the answer to that.