$_SERVER['HTTP_REFERER'] won't work here, as the page is not being reloaded - how is it possible to see when a user hit the back button, and take conditional action (e.g. redirect to a page earlier)? Maybe with JS?
$_SERVER['HTTP_REFERER'] won't work here, as the page is not being reloaded - how is it possible to see when a user hit the back button, and take conditional action (e.g. redirect to a page earlier)? Maybe with JS?
Javascript is likely going to be your only answer here to detect when a browser window is being closed or being left (it won't know you hit back per se, just that it's leaving the current page).
Remember that PHP is strictly server-sided so it can't monitor the client after processing and delivering the results. Javascript can however if the user allows it to.
I guess it depends on what you are doing. If the user is hitting back to another page on your own site you may be able to utilize sessions to see if a user had already been to that page once. But if the back button takes them off the site, there's nothing you can really do. Also most browsers now days allow users to prevent javascript from 'taking over' in a sense and changing the location back.
One method I can think of is using the prototype javascript framework, and create an event observer to observe the window being closed or location getting ready to be changed. And then injunct a check of the destination, and warn the user of leaving the site. And then have your 'correct' links change page via javascript (but still have a valid anchor underneath so that the page still works in the event javascript doesn't work)