带有pdo连接的logout.php的源代码

I am new to php, i have been created simple employee register and login form.

This my code:

index.php:

<?php
session_start();

if(isset($_SESSION['username'])){
    echo 'Welcome!', '<a href="logout.php">Logout</a>';
} else {
    echo '<a href="login.php">Login</a><br />
    <a href="register.php">Register</a>';
}
?>

register.php:

<h1>Register</h1>
<form method="POST">
    <input type="text" name="username"><br />
    <input type="password" name="password"><br />
    <input type="submit">
</form>

<?php
session_start();

    if(isset($_POST['username'], $_POST['password'])){
        require 'db.php';

        $query = dbConnect()->prepare("INSERT INTO emptable (username, password) VALUES (:username, :password)");
        $query->bindParam(':username', $_POST['username']);
        $query->bindParam(':password', $_POST['password']);

        if($query->execute()){
            header("Location: index.php");
        } else{
            echo 'ERROR';
        }
    }
?>

db.php:

<?php
    function dbConnect(){
        try{
            $username = 'root';
            $password = '';
            $conn = new pdo("mysql:host=localhost;dbname=empreg;", $username, $password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return $conn;

        }   catch(PDOException $e){
            echo 'ERROR', $e->getMessage();
        }
    }
?>

login.php:

<h1>Login</h1>
<form method="POST">
    <input type="text" name="username"><br />
    <input type="password" name="password"><br />
    <input type="submit">
</form>

<?php
session_start();
    if(isset($_POST['username'], $_POST['password'])){
        require 'db.php';

        $query = dbConnect()->prepare("SELECT username, password FROM emptable WHERE username=:username AND password=:password");
        $query->bindParam(':username', $_POST['username']);
        $query->bindParam(':password', $_POST['password']);
        $query->execute();

        if($row = $query->fetch()){
            $_SESSION['username'] = $row['username'];
            header("Location: index.php");
        }
    }
?>

According to my above, how can i create logout.php? I am blank.

Can anyone help me?

For secure processing, i had chosen these source code from online.

Any help would be highly appreciated.

Thanks in advance.

You can use the two following functions to clear session details:

<?php
    // remove all session variables
    session_unset(); 

    // destroy the session 
    session_destroy(); 
?>

Another way of doing it is just using

// make sure you don't do unset($_SESSION);
unset($_SESSION['username']); 

session_destroy();