0

Is there some indicator available in PHP to find out, if the user arrived at the current page by pressing the Back-Button of his browser?

This is the current setup of the page: The user currently navigates the website via a search or category page that uses ajax based filters. When clicking a filter, the result part of the search page is updated and the active filters are stored in the session.

Everytime the user starts a new search or a new category page a GET parameter is sent with the url, that makes the website remove the filters.

The problem is now, that when the user applied some filters, then clicks on a result and then uses the back button, the page treats this, as if a new search or category was started (removes the filters), since the GET Parameter is still in place.

My idea is to somehow detect, that the user navigated to this current page by using the back button and to disable the reset of the session in this particular case, so the user sees his filtered result list again. If this was possible somehow within the PHP code, it would safe me plenty of time.

Levi Pike
  • 133
  • 6
  • Sounds like you should rather preserve the current state of your filter settings in the URL, so that you can read it back from there. Keyword HTML5 History API. – CBroe Dec 08 '20 at 11:25
  • I wouldn't mix ajax and html events in these scenarios as you end up in this situations. Why don't you just capture history.back() to restore your filter (loaded, unhidden, ...) and avoid the whole trip to the server? – Alwin Kesler Dec 08 '20 at 12:06
  • It was an already existing application and I did not want to recode the whole page. I was hoping for a fast and easy solution within the PHP code. The JS based solution I found does the job very well, too. Thank you for taking the time. – Levi Pike Dec 10 '20 at 10:05

2 Answers2

0

You can try this to see how the navigation to your page was done.

PerformanceNavigation.type [DEPRECATED but link for you to see an overview]

Up to date for navigation type

0

I ended up not using PHP for this. Instead I used Javascripts history.replaceState() to replace the current url with one without this particular GET Parameter that would remove the filters. So in case of a back button navigation, the url is loaded without it and the filters are still applied.

Levi Pike
  • 133
  • 6