So, it seems I got it to work!
I started from this topic
http://www.zubrag.com/forum/index.php/topic,476.0.html and I've made some changes. I hope this can be useful to someone else.
1. Insert this lines at the top of the to-be-protected document, after the include statement (modify red text to fit your needs):
<?php
session_start();
if ($_SESSION['username'] == "") {
$_SESSION['username'] = $login;
}
$
yourvariable= $_SESSION['username'];
?>
This is to set a variable that won't be resetted after reloading the page and that can be used across the document with echo or <?=.... ?>.
2. Modify password_protect.php adding some lines as follow (in red):
// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
header('Location: ' . LOGOUT_URL);
session_start();
$_SESSION = array();
session_destroy(); exit();
}
This is to unset the variable and to reset the session so you can logout and login again with a different username and have it stored as a new value for $yourvariable without the need of closing and reopening your browser.
I tested it with Firefox, Internet Explorer and Chrome and for me is working perfectly.
I'm just a newbie to php so I'm not sure if this can create problems with other elements.......
Hope it helps!!