Ensure the call to set cookies is the first thing processed.
So this:
setcookie('username', "", time() - (60 * 60 * 24 * 365));
setcookie('password', "", time() - (60 * 60 * 24 * 365));
should be called as soon as possible, before any output.
To fix this all you may need to do is remove:
and test it.
Then re-add it in the relevant php file using:
echo '<div class="login">';