How to clean the html pages opened in a session?

46 Views Asked by At

A consult please, I have done a login page which open the application page and from this page I can go to other pages, I started a session, when I clear the session and back to login page stayed in the history the last page opened from application page, clicking in the arrow forward I can go to such page, it is wrong!, how could I delete such last page?, my goal, when I finish the session is to delete the history of the last page opened from the application page.

I thank you in advance for your help.

I am beginner programming Html, I dont have ideas to resolve this problem.

1

There are 1 best solutions below

0
Daidon On

IF you simply want to protect a page:

Depending on your session validation, do this on your "protected" sites:

<?php

session_start();
// Here you need to check your login state, eg if "login" is set and not null
if (!isset($_SESSION['login'])) { 
    header("Location: https://some.url");
    exit();
}

On logout.php

<?php

session_start();

session_destroy();
header("Location: https://some.url"); // can be login page
exit(); // make sure to not do anything else after this

See this answer to handle Caching.

IF you need to really clear the BROWSER HISTORY:

There are is no "good" way, although, there are some options:

Option 1: Navigate with window.location.replace(url)

<a href="javascript: window.location.replace('https://google.com')">Google</a>

If you click that link, it will replace the current session entry in the browser history. You cannot go "back" anymore from Google to the origin of this link. Instead, you would be brought back to the page before.

Option 2: use the chrome history api:

Specifically, it should be enough to call: browser.history.deleteAll(); But this is not supported on all browsers, see their supported section.