Good afternoon. There is a bulletin board. When you load the page shows a certain limit of ads. There is a "Next" button when clicking on which is accessed through ajax to a php file that rakes out the next portion of ads. Values ​​are transferred from which position to select records for LIMIT.

Since the data loading is dynamic, the initial amount is displayed when switching to another page and then returning to the page with ads.

The task is when returning to display the number of ads that have been uploaded.

I tried to implement the institution in the session variable how many ads were loaded. But there are problems: 1) The session lifetime - clicking once, at subsequent visits (in an hour, a day, etc.) will output a footcloth, which is not good. Alternatively, you can add a time stamp and compare it with the current one - if older than 1 minute, reset the variable. 2) For each category, you will need to create your own variable in the session. With a large attendance number of variables in the session will grow very much.

Has anyone come across a similar one or can someone with a fresh look suggest a more optimal solution?

  • why session and not cookies? Cookies can live as long as possible. I don’t know how many stores I store localStorage, but I think it also works - BOPOH
  • Do you want to implement classic page navigation without a button further? In this case, the user himself could manage the state - scrolling first or from a specific page. There is another ambush with the session. What if the user opens two or more tabs? - cheops

1 answer 1

@BOPOH gave a generally intelligible comment: use cookies and / or localStorage. The latter works on the same principle as cookies (storage time, etc.).

There is another very good option - Zend_Session . If you fail to use it as a plug-in library, then at least take an algorithm and implement your tool. The idea there is that the session can assign a lifetime and / or number of calls to it (the so-called jumps - hops). Suppose you want a session variable to live before the first call to it. Assign hops = 1 and do not think about anything else.

You can read about the capabilities of this tool here: http://framework.zend.com/manual/1.12/ru/zend.session.advanced_usage.html (subsection "Namespace Lifetime").