Search code examples
phpajaxlaravelsession-variables

Laravel: Show message(alert) on all open tabs, if session variable changed


Laravel Version: 5.2.45

PHP Version: ^5.4

I have a session variable named f_year. It stores the financial year in the session. This can be changed by the user. On changing the f_year, the session is reset and page is reloaded.

The problem is that, user changes the f_year in one tab and without refreshing the other tab, saves the data. And the year is mismatched.

Is it possible to show an alert on other open tabs: Your Financial Year has changed. Please reload the page to continue.


Solution

  • Well, the other day I ran into a similar issue. What I did was I first set the cookie and a session variable (using PHP). Then I used the JQuery to get the cookie value. The JQuery cookie method, fetches the current cookie set(irrespective of the browser tab).

    Then I compared these two values and alerted the user about the mismatched settings.

    Hope that helps!