I want to put a link in a button that goes to last page. But it is common that people go to other sites between the present page and last page in my web. So, is there a way to say something like go to history the first you find between three pages that I select: a.php, b.php, c.php?
Share
No, I am pretty sure you cannot do that. Anything that let you access the history of the browser would be a security risk in my opinion.
Anyway, if you want a link that goes to the last page that they visited on your site then I suggest you track it somewhere. For example, on each page load you could store the page in a session variable. This value could then be queried when they click the “last page” link.
With a session variable though you do have timeout concerns. If you need something more long term you could consider using a cookie, but be aware there are new laws that force you to notify any user that you are using cookies to store information like this.
Alternatively, if the user is a registered user (and has a login) then you could store the last page in the database.
Of course, doing this on a page load means you have to actually track the last two pages (because you will also be tracking the current page too).
Again, another alternative is you could pass the last page url around each page as a url parameter – much like the common “returnurl” that some sites use when redirecting to a login page