I've added user logins to my intranet but am trying to figure out how to allow them to logout from a link on the main page. I want them to click on a link called 'LogOut'. When this happens, I want the page to refresh and show that nobody is logged in.
I created the following function and put it in my functions.php file:
// Logout of Intranet
function Logout($user_name) {
session_unregister('user_name');
}
The index page has the following code in it:
session_start();
$session_name = session_id('user_name');
if ($user_name) {
$sql = "SELECT first FROM employees WHERE user_name = '$user_name'";
$result = db_query($sql);
$myrow = db_fetch_array($result);
$first = $myrow['first'];
echo "<TD align='left'><P class=welcometext>Welcome back, <B>$first</B>!</P></TD>
<TD align='right'><P class=welcometext><a href='index.php'>Logout</A></P></TD>\n";
} else {
echo "<TD align='left'><P class=welcometext>You are not logged in yet.</P></TD>
<TD align='right'><P class=welcometext><a href='account/login.php'>Login</A></P></TD>\n";
}
Anyone have any ideas?