Logging out users securely Is there anything I need to add or is this the best security possible?

&lt;?php

//Get Sessions Prepared;
session_start();

//If logged in, Logout;
if(!empty($_SESSION['username'])) {

    //Remove Sessions to Logout the user;
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
    session_destroy();

} else {

    //If not logged in redirect to Homepage;
    header("Location: http://gameshare.io/login");

}

?&gt;
Is there anything I need to add or is that the best security im looking at?


There really isn't much that you can do wrong here. You correctly tell the browser to delete the cookie, and there isn't more that you can do.

But if this is all your logout code, you are vulnerable to CSRF logout. It is debatable if this is a security issue; some argue that it is not, as cookies may be forcefully deleted by overflowing the cookie jar, but that's really a browser issue that may or may not exist on the client side, so to be on the save side, you should add CSRF protection. 

As a matter of best practice, you should also always die after a header redirect, as a client doesn't have to follow the redirect and code afterwards will be executed. This doesn't seem to be an issue now, but it may be in the future.

Other than that, your code is fine, but I would remove all your comments, they are just repeating what the code already says. If you want structured and named code blocks, just add functions.