Unable to disconnect php

advertisements

When an admin is logged in , the admin will have a admin page on the nav bar. When the member is logged in, the member will have a profile page on the nav bar.

However, lets say when the admin logged out, it will goes to a logout page hat says logged out and when the administrator goes back to the home page, the administrator is still logged in and the admin page is still on the navbar.

This is my codes for the login and logout.

<?php
//checks if login session variable exist? If it does, display Logout
session_start();
if(isset($_SESSION['login']) && $_SESSION['login']!="") {
    //link to page logout.php and displays the word Logout + username
    echo"<li><a href='logout.php'>Logout ".$_SESSION['login']."</a></li>";
    if(isset($_SESSION['login'])&& $_SESSION['usertype'] !="admin") {
        echo ("<li><a href='profile.php'>Profile</a></li>");
    } else {
        echo ("<li><a href='AdminPage.php'>Administrator</a></li>");
    }
    if($_SESSION['login'] == "") {
        header("Location:login.php");
    }
    if($_SESSION['login'] != "" && $_SESSION['usertype'] =="member") {
        header("location:home.php");
    }
} else {
    //else link to pagelogin.php and display the word Login
    echo("<li><a href ='pagelogin.php'>Login</a></li>");
}
?>

How do I rectify the error so that when the user is logged in the user can log out successfully.


in your logout.php file you just need to do the basic:

<?php

session_start();

session_destroy();

header("Location: pagelogin.php"); // or whatever your login file is called
?>