It looks like you need to send some headers stating that they are no longer authorized. So...
if(!isset($_SERVER['PHP_AUTH_USER']) || $_GET['logout']) {
header("WWW-Authenticate: Basic realm=\"YOUR_REALM\"");
header("Status: 401 Unauthorized");
header("HTTP-Status: 401 Unauthorized");
if($_GET['logout']) echo "You have logged out.\n";
else echo "A MESSAGE FOR IF THEY HIT THE CANCEL BUTTON\n";
exit;
}